subcommands.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "redismodule.h"
  2. #define UNUSED(V) ((void) V)
  3. int cmd_set(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
  4. UNUSED(argv);
  5. UNUSED(argc);
  6. RedisModule_ReplyWithSimpleString(ctx, "OK");
  7. return REDISMODULE_OK;
  8. }
  9. int cmd_get(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
  10. UNUSED(argv);
  11. UNUSED(argc);
  12. RedisModule_ReplyWithSimpleString(ctx, "OK");
  13. return REDISMODULE_OK;
  14. }
  15. int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
  16. REDISMODULE_NOT_USED(argv);
  17. REDISMODULE_NOT_USED(argc);
  18. int spec_id;
  19. if (RedisModule_Init(ctx, "subcommands", 1, REDISMODULE_APIVER_1)== REDISMODULE_ERR)
  20. return REDISMODULE_ERR;
  21. if (RedisModule_CreateCommand(ctx,"subcommands.bitarray",NULL,"",0,0,0) == REDISMODULE_ERR)
  22. return REDISMODULE_ERR;
  23. if (RedisModule_CreateSubcommand(ctx,"subcommands.bitarray","set",cmd_set,"",0,0,0) == REDISMODULE_ERR)
  24. return REDISMODULE_ERR;
  25. if (RedisModule_AddCommandKeySpec(ctx,"subcommands.bitarray|set","write",&spec_id) == REDISMODULE_ERR)
  26. return REDISMODULE_ERR;
  27. if (RedisModule_SetCommandKeySpecBeginSearchIndex(ctx,"subcommands.bitarray|set",spec_id,1) == REDISMODULE_ERR)
  28. return REDISMODULE_ERR;
  29. if (RedisModule_SetCommandKeySpecFindKeysRange(ctx,"subcommands.bitarray|set",spec_id,0,1,0) == REDISMODULE_ERR)
  30. return REDISMODULE_ERR;
  31. if (RedisModule_CreateSubcommand(ctx,"subcommands.bitarray","get",cmd_get,"",0,0,0) == REDISMODULE_ERR)
  32. return REDISMODULE_ERR;
  33. if (RedisModule_AddCommandKeySpec(ctx,"subcommands.bitarray|get","read",&spec_id) == REDISMODULE_ERR)
  34. return REDISMODULE_ERR;
  35. if (RedisModule_SetCommandKeySpecBeginSearchIndex(ctx,"subcommands.bitarray|get",spec_id,1) == REDISMODULE_ERR)
  36. return REDISMODULE_ERR;
  37. if (RedisModule_SetCommandKeySpecFindKeysRange(ctx,"subcommands.bitarray|get",spec_id,0,1,0) == REDISMODULE_ERR)
  38. return REDISMODULE_ERR;
  39. /* Sanity */
  40. RedisModule_Assert(RedisModule_CreateSubcommand(ctx,"bitarray","get",NULL,"",0,0,0) == REDISMODULE_ERR);
  41. RedisModule_Assert(RedisModule_CreateSubcommand(ctx,"subcommands.bitarray","get",NULL,"",0,0,0) == REDISMODULE_ERR);
  42. RedisModule_Assert(RedisModule_CreateSubcommand(ctx,"subcommands.bitarray|get","get",NULL,"",0,0,0) == REDISMODULE_ERR);
  43. return REDISMODULE_OK;
  44. }