Common Commands
Key Commands
| Command | Description |
|---|---|
SET key value | Set a key to hold a string value. |
GET key | Get the value of a key. |
DEL key | Delete a key. |
EXISTS key | Check if a key exists. |
EXPIRE key seconds | Set a timeout on a key. |
TTL key | Get the remaining time to live of a key. |
KEYS pattern | Find all keys matching a pattern (e.g., user:*). |
TYPE key | Determine the type stored at key. |
String Commands
| Command | Description |
|---|---|
APPEND key value | Append a value to a string key. |
INCR key | Increment a key's integer value by one. |
DECR key | Decrement a key's integer value by one. |
MGET key1 key2 | Get values of multiple keys. |
MSET key1 value1 key2 value2 | Set multiple keys at once. |
Hash Commands
| Command | Description |
|---|---|
HSET key field value | Set the value of a hash field. |
HGET key field | Get the value of a hash field. |
HMSET key field1 value1 ... | Set multiple fields in a hash. (Deprecated, use HSET instead) |
HGETALL key | Get all fields and values in a hash. |
HDEL key field | Delete one or more hash fields. |
HEXISTS key field | Determine if a hash field exists. |
field: the field inside the hash to set
If you want to set multiple fields at once, you can do:
HSET name firstName masum lastName billah
List Commands
| Command | Description |
|---|---|
LPUSH key value | Insert value at the head of the list. |
RPUSH key value | Insert value at the tail of the list. |
LPOP key | Remove and get the first element. |
RPOP key | Remove and get the last element. |
LRANGE key start stop | Get elements between two indices. |
LLEN key | Get the length of the list. |
Set Commands
| Command | Description |
|---|---|
SADD key member | Add one or more members to a set. |
SMEMBERS key | Get all members of a set. |
SREM key member | Remove one or more members from a set. |
SISMEMBER key member | Check if a member exists in the set. |
SCARD key | Get the number of members. |
Sorted Set (ZSet) Commands
| Command | Description |
|---|---|
ZADD key score member | Add a member with a score. |
ZRANGE key start stop | Get members by index range. |
ZRANGEBYSCORE key min max | Get members by score range. |
ZREM key member | Remove member from sorted set. |
ZCARD key | Get number of members. |
Pub/Sub Commands
| Command | Description |
|---|---|
PUBLISH channel message | Post a message to a channel. |
SUBSCRIBE channel | Subscribe to a channel. |
UNSUBSCRIBE channel | Unsubscribe from a channel. |
Server/Utility Commands
| Command | Description |
|---|---|
PING | Test connection. |
INFO | Get information about the server. |
FLUSHALL | Delete all keys in all databases. |
FLUSHDB | Delete all keys in the current DB. |
MONITOR | See all requests received by the server in real time. |