-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis.c
124 lines (90 loc) · 3.2 KB
/
redis.c
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
113
114
115
116
117
118
119
120
121
122
123
124
// get
redisReply *get_attr(redisContext *c, const char *path) {
return redisCommand(c,"HGET %s attr", path);
}
redisReply *get_size(redisContext *c, const char *path) {
return redisCommand(c,"HGET %s size", path);
}
redisReply *get_uid(redisContext *c, const char *path) {
return redisCommand(c,"HGET %s uid", path);
}
redisReply *get_gid(redisContext *c, const char *path) {
return redisCommand(c,"HGET %s gid", path);
}
redisReply *get_symlink(redisContext *c, const char *path) {
return redisCommand(c,"HGET %s symlink", path);
}
long long get_node(redisContext *c, const char *path) {
redisReply *reply=redisCommand(c,"HGET %s node", path);
if(reply->str==NULL)
return 0;
long long node=atoll(reply->str);
freeReplyObject(reply);
return node;
}
redisReply *get_chunk(redisContext *c, long long node, unsigned long int chunk) {
return redisCommand(c,"HGET %lld chunk%d", node,chunk);
}
redisReply *get_names1(redisContext *c, const char *path) {
return redisCommand(c,"KEYS %s/*",path);
}
redisReply *get_names2(redisContext *c, const char *path) {
return redisCommand(c,"KEYS /*",path);
}
// set
redisReply *set_attr(redisContext *c, const char *path, mode_t mode) {
return redisCommand(c,"HSET %s attr %d", path, mode);
}
redisReply *set_size(redisContext *c, const char *path, unsigned long int size) {
return redisCommand(c,"HSET %s size %d", path, size);
}
redisReply *set_uid(redisContext *c, const char *path, uid_t uid) {
return redisCommand(c,"HSET %s uid %d", path, uid);
}
redisReply *set_gid(redisContext *c, const char *path, gid_t gid) {
return redisCommand(c,"HSET %s gid %d", path, gid);
}
redisReply *set_symlink(redisContext *c, const char *path, const char *symlink) {
return redisCommand(c,"HSET %s symlink %s", path, symlink);
}
redisReply *set_node(redisContext *c, const char *path, long long node) {
return redisCommand(c,"HSET %s node %lld", path, node);
}
redisReply *set_chunk(redisContext *c, long long node, unsigned long int chunk, char *buff) {
return redisCommand(c,"HSET %lld chunk%d %b", node, chunk,buff, CHUNK_SIZE);
}
// del
redisReply *del_attr(redisContext *c, const char *path) {
return redisCommand(c,"HDEL %s attr", path);
}
redisReply *del_size(redisContext *c, const char *path) {
return redisCommand(c,"HDEL %s size", path);
}
redisReply *del_uid(redisContext *c, const char *path) {
return redisCommand(c,"HDEL %s uid", path);
}
redisReply *del_gid(redisContext *c, const char *path) {
return redisCommand(c,"HDEL %s gid", path);
}
redisReply *del_name(redisContext *c, const char *path) {
return redisCommand(c,"DEL %s", path);
}
redisReply *del_chunk(redisContext *c, long long node, unsigned long int chunk) {
return redisCommand(c,"HDEL %lld chunk%d", node,chunk);
}
redisReply *del_node(redisContext *c, long long node) {
return redisCommand(c,"DEL %lld ", node);
}
// mgmt
redisReply *flushdb(redisContext *c) {
return redisCommand(c, "flushdb");
}
long long get_free_node(redisContext *c) {
redisReply *reply = redisCommand(c, "INCR free_node=1000");
long long ret = reply->integer;
freeReplyObject(reply);
return ret;
}
redisReply *re_name(redisContext *c, const char *from, const char *to) {
return redisCommand(c,"RENAME %s %s", from, to);
}