summaryrefslogtreecommitdiff
path: root/src/t_hash.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-06-29 17:38:46 +0200
committerantirez <antirez@gmail.com>2017-06-29 17:38:46 +0200
commit01a4b9892d0922eeafbb1bfba0f9fa70bf1a2f3b (patch)
tree81b6901562c28e0f80fe6b40587a4595067782af /src/t_hash.c
parent634c64dd1833549a31e62405e7dc835c7bc6fa39 (diff)
downloadredis-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/t_hash.c')
-rw-r--r--src/t_hash.c32
1 files changed, 14 insertions, 18 deletions
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++;