| 33 | }; |
| 34 | |
| 35 | int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { |
| 36 | if (RedisModule_Init(ctx,"timer-spawn",1,REDISMODULE_APIVER_1) |
| 37 | == REDISMODULE_ERR) return REDISMODULE_ERR; |
| 38 | |
| 39 | enum TimerOrder mode; |
| 40 | if (argc >= 1){ |
| 41 | const char * modeString = RedisModule_StringPtrLen(argv[0], NULL); |
| 42 | if (strcmp(modeString, "ascending") == 0){ |
| 43 | mode = TIMERS_ASCENDING; |
| 44 | } else if (strcmp(modeString, "descending") == 0){ |
| 45 | mode = TIMERS_DESCENDING; |
| 46 | } else if (strcmp(modeString, "same") == 0){ |
| 47 | mode = TIMERS_SAME; |
| 48 | } else { |
| 49 | RedisModule_Log(ctx, "warning", "Invalid mode specified as first argument. Valid modes are: ascending, descending, and same"); |
| 50 | return REDISMODULE_ERR; |
| 51 | } |
| 52 | } else { |
| 53 | mode = TIMERS_DESCENDING; |
| 54 | } |
| 55 | |
| 56 | long long user_timer_count; |
| 57 | total_timer_count = (argc >= 2 && RedisModule_StringToLongLong(argv[1], &user_timer_count) == REDISMODULE_OK) ? |
| 58 | (long)user_timer_count : 2500; |
| 59 | |
| 60 | if (RedisModule_CreateCommand(ctx,"timer.elapsed", elapsed,"",0,0,0) == REDISMODULE_ERR) |
| 61 | return REDISMODULE_ERR; |
| 62 | |
| 63 | for (long i = 0; i < total_timer_count; i++){ |
| 64 | mstime_t period; |
| 65 | if (mode == TIMERS_ASCENDING){ |
| 66 | period = i; |
| 67 | } else if (mode == TIMERS_DESCENDING){ |
| 68 | period = total_timer_count - i; |
| 69 | } else if (mode == TIMERS_SAME){ |
| 70 | period = total_timer_count; |
| 71 | } |
| 72 | RedisModule_CreateTimer(ctx, period, timerHandler, NULL); |
| 73 | } |
| 74 | |
| 75 | return REDISMODULE_OK; |
| 76 | } |
nothing calls this directly
no test coverage detected