Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
92b27fe9
Commit
92b27fe9
authored
Mar 15, 2010
by
antirez
Browse files
An interesting refactoring + more expressive internal API
parent
653c9240
Changes
4
Hide whitespace changes
Inline
Side-by-side
Changelog
View file @
92b27fe9
2010-03-15 Fixed the same problem in ZREVRANK
2010-03-15 Fixed a ZRANK bug
2010-03-15 zipmap to hash conversion in HSET
2010-03-14 max zipmap entries and max zipmap value parameters added into INFO output
2010-03-14 HDEL and some improvement in DEBUG OBJECT command
2010-03-14 Append only file support for hashes
...
...
redis-cli.c
View file @
92b27fe9
...
...
@@ -148,6 +148,7 @@ static struct redisCommand cmdTable[] = {
{
"hset"
,
4
,
REDIS_CMD_MULTIBULK
},
{
"hget"
,
3
,
REDIS_CMD_BULK
},
{
"hdel"
,
3
,
REDIS_CMD_BULK
},
{
"hlen"
,
2
,
REDIS_CMD_INLINE
},
{
NULL
,
0
,
0
}
};
...
...
redis.c
View file @
92b27fe9
...
...
@@ -682,6 +682,7 @@ static void zrevrankCommand(redisClient *c);
static void hsetCommand(redisClient *c);
static void hgetCommand(redisClient *c);
static void hdelCommand(redisClient *c);
static void hlenCommand(redisClient *c);
static void zremrangebyrankCommand(redisClient *c);
static void zunionCommand(redisClient *c);
static void zinterCommand(redisClient *c);
...
...
@@ -746,6 +747,7 @@ static struct redisCommand cmdTable[] = {
{"hset",hsetCommand,4,REDIS_CMD_BULK|REDIS_CMD_DENYOOM,1,1,1},
{"hget",hgetCommand,3,REDIS_CMD_BULK,1,1,1},
{"hdel",hdelCommand,3,REDIS_CMD_BULK,1,1,1},
{"hlen",hlenCommand,2,REDIS_CMD_INLINE,1,1,1},
{"incrby",incrbyCommand,3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM,1,1,1},
{"decrby",decrbyCommand,3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM,1,1,1},
{"getset",getsetCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM,1,1,1},
...
...
@@ -2480,6 +2482,14 @@ static void addReplyLong(redisClient *c, long l) {
addReplySds(c,sdsnewlen(buf,len));
}
static void addReplyUlong(redisClient *c, unsigned long ul) {
char buf[128];
size_t len;
len = snprintf(buf,sizeof(buf),":%lu\r\n",ul);
addReplySds(c,sdsnewlen(buf,len));
}
static void addReplyBulkLen(redisClient *c, robj *obj) {
size_t len;
...
...
@@ -2739,6 +2749,26 @@ static robj *lookupKeyWrite(redisDb *db, robj *key) {
return lookupKey(db,key);
}
static robj *lookupKeyReadOrReply(redisClient *c, robj *key, robj *reply) {
robj *o = lookupKeyRead(c->db, key);
if (!o) addReply(c,reply);
return o;
}
static robj *lookupKeyWriteOrReply(redisClient *c, robj *key, robj *reply) {
robj *o = lookupKeyWrite(c->db, key);
if (!o) addReply(c,reply);
return o;
}
static int checkType(redisClient *c, robj *o, int type) {
if (o->type != type) {
addReply(c,shared.wrongtypeerr);
return 1;
}
return 0;
}
static int deleteKey(redisDb *db, robj *key) {
int retval;
...
...
@@ -6019,7 +6049,7 @@ static void hgetCommand(redisClient *c) {
}
static void hdelCommand(redisClient *c) {
robj
*
o
=
lookupKey
Read
(
c
->
db
,
c
->
argv
[
1
]);
robj *o = lookupKey
Write
(c->db,c->argv[1]);
if (o == NULL) {
addReply(c,shared.czero);
...
...
@@ -6043,6 +6073,18 @@ static void hdelCommand(redisClient *c) {
}
}
static void hlenCommand(redisClient *c) {
robj *o;
unsigned long len;
if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.czero)) == NULL ||
checkType(c,o,REDIS_HASH)) return;
len = (o->encoding == REDIS_ENCODING_ZIPMAP) ?
zipmapLen((unsigned char*)o->ptr) : dictSize((dict*)o->ptr);
addReplyUlong(c,len);
}
static void convertToRealHash(robj *o) {
unsigned char *key, *val, *p, *zm = o->ptr;
unsigned int klen, vlen;
...
...
redis.tcl
View file @
92b27fe9
...
...
@@ -20,14 +20,14 @@ array set ::redis::multibulkarg {}
# Flag commands requiring last argument as a bulk write operation
foreach redis_bulk_cmd
{
set setnx rpush lpush lset lrem sadd srem sismember echo getset smove zadd zrem zscore zincrby append zrank zrevrank
set setnx rpush lpush lset lrem sadd srem sismember echo getset smove zadd zrem zscore zincrby append zrank zrevrank
hget hdel
}
{
set ::redis::bulkarg
(
$redis
_bulk_cmd
)
{}
}
# Flag commands requiring last argument as a bulk write operation
foreach redis_multibulk_cmd
{
mset msetnx
mset msetnx
hset
}
{
set ::redis::multibulkarg
(
$redis
_multibulk_cmd
)
{}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment