This repository is forked from RedisModulesSDK.
The Redis 4.x has the feature of Modules.Modules allow us to implement new Redis commands at a speed and with features similar to what can be done inside the core itself.
In this repository, I implement some customized commands in file example/module.c
.
- Redis version >= 4.0.0
- Linux | MacOS
- C
- Make the
module.so
.
$ git clone [email protected]:Sidfate/MyRedisModules.git
$ cd ./MyRedisModules/example
$ make all
- Start redis server with
module.so
.
$ /path/to/redis-server --loadmodule ./module.so
- Test for command
$ redis-cli
127.0.0.1:6379> MY.TEST
PASS
-
MY.HGETSET
This command extends from RedisModulesSDK.
Atomically set a value in a HASH key to and return its value before the HSET.
Usage:
MY.HGETSET <key> <element> <value>
Test:
$ redis-cli 127.0.0.1:6379> MY.HGETSET foo bar baz (nil) 127.0.0.1:6379> MY.HGETSET foo bar vaz "baz"
-
MY.LDEL
Delete list element by the index
Usage:
MY.LDEL <key> <index>
Test:
$ redis-cli 127.0.0.1:6379> RPUSH mylist "test1" (integer) 1 127.0.0.1:6379> RPUSH mylist "test2" (integer) 2 127.0.0.1:6379> RPUSH mylist "test1" (integer) 3 127.0.0.1:6379> LRANGE mylist 0 -1 1) "test1" 2) "test2" 3) "test1" 127.0.0.1:6379> MY.LDEL mylist 0 OK 127.0.0.1:6379> LRANGE mylist 0 -1 1) "test2" 2) "test1"
MIT