diff options
author | antirez <antirez@gmail.com> | 2016-04-11 17:12:11 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2016-05-10 06:40:07 +0200 |
commit | 11b3df24cb77c382c956c845151b1b8f0252c9f2 (patch) | |
tree | 52883f74eb23ce480a0f41baf721fcce62fe6e67 /src/modules/helloworld.c | |
parent | f4e0129fa9c127700bd2193b696d9051f391b2ef (diff) | |
download | redis-11b3df24cb77c382c956c845151b1b8f0252c9f2.tar.gz |
Modules: expire API and documentation.
Diffstat (limited to 'src/modules/helloworld.c')
-rw-r--r-- | src/modules/helloworld.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/modules/helloworld.c b/src/modules/helloworld.c index 477a12727..7480415ea 100644 --- a/src/modules/helloworld.c +++ b/src/modules/helloworld.c @@ -303,6 +303,29 @@ int HelloToggleCase_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, return REDISMODULE_OK; } +/* HELLO.MORE.EXPIRE key milliseconds. + * + * If they key has already an associated TTL, extends it by "milliseconds" + * milliseconds. Otherwise no operation is performed. */ +int HelloMoreExpire_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { + RedisModule_AutoMemory(ctx); /* Use automatic memory management. */ + if (argc != 3) return RedisModule_WrongArity(ctx); + + mstime_t addms, expire; + + if (RedisModule_StringToLongLong(argv[2],&addms) != REDISMODULE_OK) + return RedisModule_ReplyWithError(ctx,"ERR invalid expire time"); + + RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1], + REDISMODULE_READ|REDISMODULE_WRITE); + expire = RedisModule_GetExpire(key); + if (expire != REDISMODULE_NO_EXPIRE) { + expire += addms; + RedisModule_SetExpire(key,expire); + } + return RedisModule_ReplyWithSimpleString(ctx,"OK"); +} + /* This function must be present on each Redis module. It is used in order to * register the commands into the Redis server. */ int RedisModule_OnLoad(RedisModuleCtx *ctx) { @@ -353,5 +376,9 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx) { HelloToggleCase_RedisCommand) == REDISMODULE_ERR) return REDISMODULE_ERR; + if (RedisModule_CreateCommand(ctx,"hello.more.expire", + HelloMoreExpire_RedisCommand) == REDISMODULE_ERR) + return REDISMODULE_ERR; + return REDISMODULE_OK; } |