Redis - keshavbaweja-git/guides GitHub Wiki

Set up a redis server and redis-cli container

docker network create redis-net
docker run -d --name redis-server-1 --network redis-net -p 6379:6379 --mount source=redis-data,target=/data \
redis redis-server --appendonly yes
docker run -it --name redis-client-1 --network redis-net redis redis-cli -h redis-server-1
Description Command
List all keys keys *
List cluster nodes redis-cli -h <ip-cluster-node> -p <port-cluster-node> cluster nodes
Check cluster health redis-cli --cluster check <ip-cluster-node>:<port-cluster-node>
Connect to a cluster node redis-cli -c -h <ip-cluster-node> -p <port-cluster-node>
Cluster information cluster info
Cluster nodes cluster nodes
Cluster replicas cluster replicas
Cluster slot distribution cluster slots
Hash slot for a key cluster keyslot <key>
# Redis supports 5 data types. You need to know what type of value that a key maps to, as for each data type, the command to retrieve it is different. Here are the commands to retrieve key value:
if value is of type string -> GET <key>
if value is of type hash -> HGETALL <key>
if value is of type lists -> lrange <key> <start> <end>
if value is of type sets -> smembers <key>
if value is of type sorted sets -> ZRANGEBYSCORE <key> <min> <max>
# Use the TYPE command to check the type of value a key is mapping to:
type <key>
# Delete all keys matching users*
redis-cli --scan --pattern users:* | xargs redis-cli del
⚠️ **GitHub.com Fallback** ⚠️