diff options
author | antirez <antirez@gmail.com> | 2017-06-29 17:38:46 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2017-06-29 17:38:46 +0200 |
commit | 01a4b9892d0922eeafbb1bfba0f9fa70bf1a2f3b (patch) | |
tree | 81b6901562c28e0f80fe6b40587a4595067782af /src | |
parent | 634c64dd1833549a31e62405e7dc835c7bc6fa39 (diff) | |
download | redis-01a4b9892d0922eeafbb1bfba0f9fa70bf1a2f3b.tar.gz |
HMSET and MSET implementations unified. HSET now variadic.
This is the first step towards getting rid of HMSET which is a command
that does not make much sense once HSET is variadic, and has a saner
return value.
Diffstat (limited to 'src')
-rw-r--r-- | src/server.c | 8 | ||||
-rw-r--r-- | src/t_hash.c | 32 |
2 files changed, 18 insertions, 22 deletions
diff --git a/src/server.c b/src/server.c index 46e5bb9f7..2fff8c74f 100644 --- a/src/server.c +++ b/src/server.c @@ -144,7 +144,7 @@ struct redisCommand redisCommandTable[] = { {"substr",getrangeCommand,4,"r",0,NULL,1,1,1,0,0}, {"incr",incrCommand,2,"wmF",0,NULL,1,1,1,0,0}, {"decr",decrCommand,2,"wmF",0,NULL,1,1,1,0,0}, - {"mget",mgetCommand,-2,"r",0,NULL,1,-1,1,0,0}, + {"mget",mgetCommand,-2,"rF",0,NULL,1,-1,1,0,0}, {"rpush",rpushCommand,-3,"wmF",0,NULL,1,1,1,0,0}, {"lpush",lpushCommand,-3,"wmF",0,NULL,1,1,1,0,0}, {"rpushx",rpushxCommand,-3,"wmF",0,NULL,1,1,1,0,0}, @@ -198,11 +198,11 @@ struct redisCommand redisCommandTable[] = { {"zrank",zrankCommand,3,"rF",0,NULL,1,1,1,0,0}, {"zrevrank",zrevrankCommand,3,"rF",0,NULL,1,1,1,0,0}, {"zscan",zscanCommand,-3,"rR",0,NULL,1,1,1,0,0}, - {"hset",hsetCommand,4,"wmF",0,NULL,1,1,1,0,0}, + {"hset",hsetCommand,-4,"wmF",0,NULL,1,1,1,0,0}, {"hsetnx",hsetnxCommand,4,"wmF",0,NULL,1,1,1,0,0}, {"hget",hgetCommand,3,"rF",0,NULL,1,1,1,0,0}, - {"hmset",hmsetCommand,-4,"wm",0,NULL,1,1,1,0,0}, - {"hmget",hmgetCommand,-3,"r",0,NULL,1,1,1,0,0}, + {"hmset",hsetCommand,-4,"wmF",0,NULL,1,1,1,0,0}, + {"hmget",hmgetCommand,-3,"rF",0,NULL,1,1,1,0,0}, {"hincrby",hincrbyCommand,4,"wmF",0,NULL,1,1,1,0,0}, {"hincrbyfloat",hincrbyfloatCommand,4,"wmF",0,NULL,1,1,1,0,0}, {"hdel",hdelCommand,-3,"wF",0,NULL,1,1,1,0,0}, diff --git a/src/t_hash.c b/src/t_hash.c index a49559336..700a6233a 100644 --- a/src/t_hash.c +++ b/src/t_hash.c @@ -511,19 +511,6 @@ void hashTypeConvert(robj *o, int enc) { * Hash type commands *----------------------------------------------------------------------------*/ -void hsetCommand(client *c) { - int update; - robj *o; - - if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return; - hashTypeTryConversion(o,c->argv,2,3); - update = hashTypeSet(o,c->argv[2]->ptr,c->argv[3]->ptr,HASH_SET_COPY); - addReply(c, update ? shared.czero : shared.cone); - signalModifiedKey(c->db,c->argv[1]); - notifyKeyspaceEvent(NOTIFY_HASH,"hset",c->argv[1],c->db->id); - server.dirty++; -} - void hsetnxCommand(client *c) { robj *o; if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return; @@ -540,8 +527,8 @@ void hsetnxCommand(client *c) { } } -void hmsetCommand(client *c) { - int i; +void hsetCommand(client *c) { + int i, created = 0; robj *o; if ((c->argc % 2) == 1) { @@ -551,10 +538,19 @@ void hmsetCommand(client *c) { if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return; hashTypeTryConversion(o,c->argv,2,c->argc-1); - for (i = 2; i < c->argc; i += 2) { - hashTypeSet(o,c->argv[i]->ptr,c->argv[i+1]->ptr,HASH_SET_COPY); + + for (i = 2; i < c->argc; i += 2) + created += !hashTypeSet(o,c->argv[i]->ptr,c->argv[i+1]->ptr,HASH_SET_COPY); + + /* HMSET (deprecated) and HSET return value is different. */ + char *cmdname = c->argv[0]->ptr; + if (cmdname[1] == 's' || cmdname[1] == 'S') { + /* HSET */ + addReplyLongLong(c, created); + } else { + /* HMSET */ + addReply(c, shared.ok); } - addReply(c, shared.ok); signalModifiedKey(c->db,c->argv[1]); notifyKeyspaceEvent(NOTIFY_HASH,"hset",c->argv[1],c->db->id); server.dirty++; |