Writing a Redis module
Redis provides extensive C APIs for users to write a module. While Redis modules can be written in any language that has C binding functionalities, writing a Redis module in C language is the easiest and most straightforward method.
In this recipe, we are going to implement a Redis module, MYMODULE
, in C language with a new command ZIP
, which can be called as follows:
MYMODULE.ZIP destination_hash field_list value_list
The command takes two Redis lists and tries to create a Redis hash, whose fields are elements in field_list
and corresponding values are elements of the same index in value_list
.
For example, if field_list
is ["john", "alex", "tom"]
and value_list
is ["20", "30", "40"]
, destination_hash
will be {"john": "20", "alex": "30", "tom": 40}
. If the lengths of the two lists are not equal, the longer list will be truncated to the same length of the shorter one before creating the hash (the list itself will not change after that). If there are duplicate elements...