- Official docs from Redis https://redis.io/commands
- Nodejs Redis client https://github.com/redis/ioredis
If Redis is running on the same machine, it will connect to the default Redis server localhost
on port 6379
.
redis-cli
> SET my:key myvalue
OK
> GET my:key
"myvalue"
> RENAME my:key my:newkey
OK
> KEYS my:*
1) "my:newky"
2) "my:key"
Note: Source
Time complexity: O(N) with N being the number of keys in the database, under the assumption that the key names in the database and the given pattern have limited length. All redis commands are single thread and will block the server. The only difference is that keys has the potential of blocking server for longer when querying a large data set.
So, with version 2.8 or later, use scan is a superior alternative to keys because it does not block the server nor does it consume significant resources.
redis-cli --scan --pattern '*'
> SADD my:set hello world
(integer) 2
> SMEMBERS my:set
1) "hello"
2) "world"
spop
randomly selects a specified number then deletes themsrem
allows you to remove one or more specific members- Use
smove
to move a member from one set to another.
Read more from here.
> HSET person name Sang
(integer) 1
> HGET person name
"Sang"
> HGETALL person
1) "name"
2) "Sang"
> HDEL person name
(integer) 1
Read more about Hash group commands here.
> TTL my:key
(integer) -1
> EXPIRE my:key 10
(integer) 1