GETSET implemented

This commit is contained in:
antirez 2009-04-28 14:42:55 +02:00
parent b8b553c84f
commit a431eb74ba
2 changed files with 15 additions and 0 deletions

View File

@ -85,6 +85,7 @@ static struct redisCommand cmdTable[] = {
{"smembers",2,REDIS_CMD_INLINE},
{"incrby",3,REDIS_CMD_INLINE},
{"decrby",3,REDIS_CMD_INLINE},
{"getset",3,REDIS_CMD_BULK},
{"randomkey",1,REDIS_CMD_INLINE},
{"select",2,REDIS_CMD_INLINE},
{"move",3,REDIS_CMD_INLINE},

14
redis.c
View File

@ -356,6 +356,7 @@ static void infoCommand(redisClient *c);
static void mgetCommand(redisClient *c);
static void monitorCommand(redisClient *c);
static void expireCommand(redisClient *c);
static void getSetCommand(redisClient *c);
/*================================= Globals ================================= */
@ -391,6 +392,7 @@ static struct redisCommand cmdTable[] = {
{"smembers",sinterCommand,2,REDIS_CMD_INLINE},
{"incrby",incrbyCommand,3,REDIS_CMD_INLINE},
{"decrby",decrbyCommand,3,REDIS_CMD_INLINE},
{"getset",getSetCommand,3,REDIS_CMD_BULK},
{"randomkey",randomkeyCommand,1,REDIS_CMD_INLINE},
{"select",selectCommand,2,REDIS_CMD_INLINE},
{"move",moveCommand,3,REDIS_CMD_INLINE},
@ -2174,6 +2176,18 @@ static void getCommand(redisClient *c) {
}
}
static void getSetCommand(redisClient *c) {
getCommand(c);
if (dictAdd(c->db->dict,c->argv[1],c->argv[2]) == DICT_ERR) {
dictReplace(c->db->dict,c->argv[1],c->argv[2]);
} else {
incrRefCount(c->argv[1]);
}
incrRefCount(c->argv[2]);
server.dirty++;
removeExpire(c->db,c->argv[1]);
}
static void mgetCommand(redisClient *c) {
int j;