summaryrefslogtreecommitdiff
path: root/src/t_string.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2011-11-10 17:52:02 +0100
committerantirez <antirez@gmail.com>2011-11-10 17:52:02 +0100
commit12d293ca6edab6cc94cbd90840c629a535a12aef (patch)
treeb9f54329341874b30b495caee56d92c6bb75df4a /src/t_string.c
parentdab5332f95bd2f4fabf8e746b0998cd5bc37e448 (diff)
downloadredis-12d293ca6edab6cc94cbd90840c629a535a12aef.tar.gz
high resolution expires API modified to use separated commands. AOF transation to PEXPIREAT of all the expire-style commands fixed.
Diffstat (limited to 'src/t_string.c')
-rw-r--r--src/t_string.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/t_string.c b/src/t_string.c
index aea588728..ce6233a98 100644
--- a/src/t_string.c
+++ b/src/t_string.c
@@ -12,16 +12,17 @@ static int checkStringLength(redisClient *c, long long size) {
return REDIS_OK;
}
-void setGenericCommand(redisClient *c, int nx, robj *key, robj *val, robj *expire) {
- long seconds = 0; /* initialized to avoid an harmness warning */
+void setGenericCommand(redisClient *c, int nx, robj *key, robj *val, robj *expire, int unit) {
+ long long milliseconds = 0; /* initialized to avoid an harmness warning */
if (expire) {
- if (getLongFromObjectOrReply(c, expire, &seconds, NULL) != REDIS_OK)
+ if (getLongLongFromObjectOrReply(c, expire, &milliseconds, NULL) != REDIS_OK)
return;
- if (seconds <= 0) {
+ if (milliseconds <= 0) {
addReplyError(c,"invalid expire time in SETEX");
return;
}
+ if (unit == UNIT_SECONDS) milliseconds *= 1000;
}
if (lookupKeyWrite(c->db,key) != NULL && nx) {
@@ -30,23 +31,28 @@ void setGenericCommand(redisClient *c, int nx, robj *key, robj *val, robj *expir
}
setKey(c->db,key,val);
server.dirty++;
- if (expire) setExpire(c->db,key,(time(NULL)+seconds)*1000);
+ if (expire) setExpire(c->db,key,mstime()+milliseconds);
addReply(c, nx ? shared.cone : shared.ok);
}
void setCommand(redisClient *c) {
c->argv[2] = tryObjectEncoding(c->argv[2]);
- setGenericCommand(c,0,c->argv[1],c->argv[2],NULL);
+ setGenericCommand(c,0,c->argv[1],c->argv[2],NULL,0);
}
void setnxCommand(redisClient *c) {
c->argv[2] = tryObjectEncoding(c->argv[2]);
- setGenericCommand(c,1,c->argv[1],c->argv[2],NULL);
+ setGenericCommand(c,1,c->argv[1],c->argv[2],NULL,0);
}
void setexCommand(redisClient *c) {
c->argv[3] = tryObjectEncoding(c->argv[3]);
- setGenericCommand(c,0,c->argv[1],c->argv[3],c->argv[2]);
+ setGenericCommand(c,0,c->argv[1],c->argv[3],c->argv[2],UNIT_SECONDS);
+}
+
+void psetexCommand(redisClient *c) {
+ c->argv[3] = tryObjectEncoding(c->argv[3]);
+ setGenericCommand(c,0,c->argv[1],c->argv[3],c->argv[2],UNIT_MILLISECONDS);
}
int getGenericCommand(redisClient *c) {