diff options
author | antirez <antirez@gmail.com> | 2018-03-31 00:44:46 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2018-03-31 00:44:46 +0200 |
commit | 2f7da0fd1a70f8cc0fe2edb2b1d6f37466615457 (patch) | |
tree | 60a97ffaa06688c926b618ef9ad3d0ce69f222dc | |
parent | b85a465c25ac9065a3378bd4b5e8047a606b1f6e (diff) | |
download | redis-2f7da0fd1a70f8cc0fe2edb2b1d6f37466615457.tar.gz |
Modules Timer API: fix infinite loop and export API.
-rw-r--r-- | src/module.c | 9 | ||||
-rw-r--r-- | src/modules/Makefile | 7 | ||||
-rw-r--r-- | src/redismodule.h | 7 |
3 files changed, 20 insertions, 3 deletions
diff --git a/src/module.c b/src/module.c index 4e25f0f37..7b7fbb1fe 100644 --- a/src/module.c +++ b/src/module.c @@ -4100,10 +4100,12 @@ RedisModuleTimerID RM_CreateTimer(RedisModuleCtx *ctx, mstime_t period, RedisMod while(1) { key = htonu64(expiretime); int retval = raxInsert(Timers,(unsigned char*)&key,sizeof(key),timer,NULL); - if (retval) + if (retval) { expiretime = key; - else + break; + } else { expiretime++; + } } /* We need to install the main event loop timer if it's not already @@ -4551,4 +4553,7 @@ void moduleRegisterCoreAPI(void) { REGISTER_API(GetClusterNodeInfo); REGISTER_API(GetClusterNodesList); REGISTER_API(FreeClusterNodesList); + REGISTER_API(CreateTimer); + REGISTER_API(StopTimer); + REGISTER_API(GetTimerInfo); } diff --git a/src/modules/Makefile b/src/modules/Makefile index 1c6576c89..cffe68994 100644 --- a/src/modules/Makefile +++ b/src/modules/Makefile @@ -13,7 +13,7 @@ endif .SUFFIXES: .c .so .xo .o -all: helloworld.so hellotype.so helloblock.so testmodule.so hellocluster.so +all: helloworld.so hellotype.so helloblock.so testmodule.so hellocluster.so hellotimer.so .c.xo: $(CC) -I. $(CFLAGS) $(SHOBJ_CFLAGS) -fPIC -c $< -o $@ @@ -38,6 +38,11 @@ hellocluster.xo: ../redismodule.h hellocluster.so: hellocluster.xo $(LD) -o $@ $< $(SHOBJ_LDFLAGS) $(LIBS) -lc +hellotimer.xo: ../redismodule.h + +hellotimer.so: hellotimer.xo + $(LD) -o $@ $< $(SHOBJ_LDFLAGS) $(LIBS) -lc + testmodule.xo: ../redismodule.h testmodule.so: testmodule.xo diff --git a/src/redismodule.h b/src/redismodule.h index 85e25c7e9..47fc6668a 100644 --- a/src/redismodule.h +++ b/src/redismodule.h @@ -147,6 +147,7 @@ typedef size_t (*RedisModuleTypeMemUsageFunc)(const void *value); typedef void (*RedisModuleTypeDigestFunc)(RedisModuleDigest *digest, void *value); typedef void (*RedisModuleTypeFreeFunc)(void *value); typedef void (*RedisModuleClusterMessageReceiver)(RedisModuleCtx *ctx, const char *sender_id, uint8_t type, const unsigned char *payload, uint32_t len); +typedef void (*RedisModuleTimerProc)(RedisModuleCtx *ctx, void *data); #define REDISMODULE_TYPE_METHOD_VERSION 1 typedef struct RedisModuleTypeMethods { @@ -272,6 +273,9 @@ int REDISMODULE_API_FUNC(RedisModule_SendClusterMessage)(RedisModuleCtx *ctx, ch int REDISMODULE_API_FUNC(RedisModule_GetClusterNodeInfo)(RedisModuleCtx *ctx, const char *id, char *ip, char *master_id, int *port, int *flags); char **REDISMODULE_API_FUNC(RedisModule_GetClusterNodesList)(RedisModuleCtx *ctx, size_t *numnodes); void REDISMODULE_API_FUNC(RedisModule_FreeClusterNodesList)(char **ids); +RedisModuleTimerID REDISMODULE_API_FUNC(RedisModule_CreateTimer)(RedisModuleCtx *ctx, mstime_t period, RedisModuleTimerProc callback, void *data); +int REDISMODULE_API_FUNC(RedisModule_StopTimer)(RedisModuleCtx *ctx, RedisModuleTimerID id, void **data); +int REDISMODULE_API_FUNC(RedisModule_GetTimerInfo)(RedisModuleCtx *ctx, RedisModuleTimerID id, uint64_t *remaining, void **data); /* Experimental APIs */ #ifdef REDISMODULE_EXPERIMENTAL_API @@ -400,6 +404,9 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int REDISMODULE_GET_API(GetClusterNodeInfo); REDISMODULE_GET_API(GetClusterNodesList); REDISMODULE_GET_API(FreeClusterNodesList); + REDISMODULE_GET_API(CreateTimer); + REDISMODULE_GET_API(StopTimer); + REDISMODULE_GET_API(GetTimerInfo); #ifdef REDISMODULE_EXPERIMENTAL_API REDISMODULE_GET_API(GetThreadSafeContext); |