-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.h
112 lines (104 loc) · 3.55 KB
/
command.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* Hippo Memory Cached
* Copyright (C) 2012 heaven. All rights reserved.
*
* Hippo is a mini open-source cache daemon, mainly used in dynamic data cache.
*
* Use and distribution licensed under the BSD license. See
* the LICENSE file for full text.
*
* To learn more open-source code, visit: http://code.google.com/p/heavenmvc/
* Email: wangwei([email protected])
*/
typedef struct _hippo_client {
int fd;
time_t last_cmd_time; /* time of the last interaction, used for timeout */
}hippo_client;
typedef int command_proc(hippo_client *client,char **head_arr,int head_num);
typedef struct _hippo_command {
char *name;
command_proc *proc;
int param_num;
}hippo_command;
hippo_command *lookup_command(char *name);
void write_file_lock(char *msg);
void send_info_to_client(int client_sock, char *msg, int length);
int store_hash_data(const char* skey,unsigned ken_len,char *data, unsigned value_len, unsigned lifetime, short mode);
HashNode *fetch_hash_item(const char* skey);
int remove_hash_item(const char* skey);
int flush_hash_table();
int flush_hash_table_expire_data();int store_hash_data(const char* skey,unsigned ken_len,char *data, unsigned value_len, unsigned lifetime, short mode);
HashNode *fetch_hash_item(const char* skey);
int remove_hash_item(const char* skey);
int flush_hash_table();
int flush_hash_table_expire_data();
/**
* set key's value
* method: set
* format: <cmd> <key> <expire> <length> <value>\r\n
* cmd: set
*/
int set_command(hippo_client *client,char **head_arr,int head_num);
/**
* set key's value
* method: set
* format: <cmd> <key> <expire> <length> <value>\r\n
* cmd: modify
*/
int modify_command(hippo_client *client,char **head_arr,int head_num);
/**
* get key's value
* method: get
* format: <cmd> <key>\r\n
* cmd: get
*/
int get_command(hippo_client *client,char **head_arr,int head_num);
int del_command(hippo_client *client,char **head_arr,int head_num);
int set_list_command(hippo_client *client,char **head_arr,int head_num);
int modify_list_item_command(hippo_client *client,char **head_arr,int head_num);
int get_list_command(hippo_client *client,char **head_arr,int head_num);
int del_list_command(hippo_client *client,char **head_arr,int head_num);
/**
* clear all key and value
* method: flush
* format: <cmd>\r\n
* cmd: flush
*/
int flush_command(hippo_client *client,char **head_arr,int head_num);
int clear_expire_command(hippo_client *client,char **head_arr,int head_num);
/**
* method: version
* format: <cmd>\r\n
* cmd: version
*/
int version_command(hippo_client *client,char **head_arr,int head_num);
/**
* method: stats
* format: <cmd>\r\n
* cmd: stats
*/
int stats_command(hippo_client *client,char **head_arr,int head_num);
int persist_command(hippo_client *client,char **head_arr,int head_num);
/**
* method: quit
* format: <cmd>\r\n
* cmd: quit
*/
int quit_command(hippo_client *client,char **head_arr,int head_num);
static hippo_command cmd_table[] = {
{"set",set_command,5},
{"modify",modify_command,5},
{"get",get_command,2},
{"del",del_command,2},
{"set_list",set_list_command,5},
{"modify_list_item",modify_list_item_command,6},
{"get_list",get_list_command,2},
{"del_list",del_list_command,2},
{"flush",flush_command,1},
{"clear_expire",clear_expire_command,1},
{"version",version_command,1},
{"stats",stats_command,1},
{"persist",persist_command,1},
{"quit",quit_command,1},
{"",NULL,0}
};