If I want to add a new command to the redis server, where should I start in the source code?
Comment From: itamarhaber
Hello @MasterL-min
The easiest way to extend Redis with new commands and data structures is with a module. Please take a look at the documentation for more details and examples on writing one.
Comment From: bugwz
@MasterL-min
Also u can find the command code struct redisCommand redisCommandTable[] in src/commands.c.
Comment From: MasterL-min
Hello @MasterL-min
The easiest way to extend Redis with new commands and data structures is with a module. Please take a look at the documentation for more details and examples on writing one.
Thanks a lot,it is really easy to extend Redis with a module,and i also want to know where could I start if I want to make modifications on the command of redis itself
Comment From: itamarhaber
where could I start if I want to make modifications on the command
That depends on the command. Each command is described by a JSON file under src/commands. You can find the name of the C function each command is implemented with under the "function" field.
For example, the SET command's JSON file is at src/commands/set.json and has the value "setCommand" as the "function"'s key value: https://github.com/redis/redis/blob/7.0/src/commands/set.json#L8
If you search the code, you'll find the implementation of "setCommand" in the src/t_string.c: https://github.com/redis/redis/blob/7.0/src/t_string.c#L292
Comment From: MasterL-min
where could I start if I want to make modifications on the command
That depends on the command. Each command is described by a JSON file under src/commands. You can find the name of the C function each command is implemented with under the "function" field.
For example, the
SETcommand's JSON file is at src/commands/set.json and has the value "setCommand" as the "function"'s key value: https://github.com/redis/redis/blob/7.0/src/commands/set.json#L8If you search the code, you'll find the implementation of "setCommand" in the src/t_string.c: https://github.com/redis/redis/blob/7.0/src/t_string.c#L292
I want to know why when I only changed the const char *strflags parameter in the RedisModule_CreateCommand function in the Module sample code, it shows hellorand.so initialization failed after running the redis server. I didn't even change the content of the internal function
Comment From: MasterL-min
where could I start if I want to make modifications on the command
That depends on the command. Each command is described by a JSON file under src/commands. You can find the name of the C function each command is implemented with under the "function" field.
For example, the
SETcommand's JSON file is at src/commands/set.json and has the value "setCommand" as the "function"'s key value: https://github.com/redis/redis/blob/7.0/src/commands/set.json#L8If you search the code, you'll find the implementation of "setCommand" in the src/t_string.c: https://github.com/redis/redis/blob/7.0/src/t_string.c#L292
like the RedisModule_CreateCommand(ctx,"helloworld.rand",
HelloworldRand_RedisCommand, "fast random",
0, 0, 0) == REDISMODULE_ERR),I just change the "fast random" to the "fast send",then the redis server can not load the module correctly.
Comment From: itamarhaber
That is because "send" is a random word rather than a valid command flag. For the full list of supported command flags please refer to the docs: https://redis.io/docs/reference/modules/modules-api-ref/#redismodule_createcommand
Comment From: itamarhaber
Keep in mind that this issue tracker should be used for reporting bugs or proposing improvements to the Redis server. Questions should be directed to the community:
- the mailing list
- the
redistag at StackOverflow - /r/redis subreddit
- the irc channel #redis on freenode
Comment From: MasterL-min
That is because "send" is a random word rather than a valid command flag. For the full list of supported command flags please refer to the docs: https://redis.io/docs/reference/modules/modules-api-ref/#redismodule_createcommand
Thank you very much for your help