Skip to main content

Common Commands

Key Commands

CommandDescription
SET key valueSet a key to hold a string value.
GET keyGet the value of a key.
DEL keyDelete a key.
EXISTS keyCheck if a key exists.
EXPIRE key secondsSet a timeout on a key.
TTL keyGet the remaining time to live of a key.
KEYS patternFind all keys matching a pattern (e.g., user:*).
TYPE keyDetermine the type stored at key.

String Commands

CommandDescription
APPEND key valueAppend a value to a string key.
INCR keyIncrement a key's integer value by one.
DECR keyDecrement a key's integer value by one.
MGET key1 key2Get values of multiple keys.
MSET key1 value1 key2 value2Set multiple keys at once.

Hash Commands

CommandDescription
HSET key field valueSet the value of a hash field.
HGET key fieldGet the value of a hash field.
HMSET key field1 value1 ...Set multiple fields in a hash. (Deprecated, use HSET instead)
HGETALL keyGet all fields and values in a hash.
HDEL key fieldDelete one or more hash fields.
HEXISTS key fieldDetermine 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

CommandDescription
LPUSH key valueInsert value at the head of the list.
RPUSH key valueInsert value at the tail of the list.
LPOP keyRemove and get the first element.
RPOP keyRemove and get the last element.
LRANGE key start stopGet elements between two indices.
LLEN keyGet the length of the list.

Set Commands

CommandDescription
SADD key memberAdd one or more members to a set.
SMEMBERS keyGet all members of a set.
SREM key memberRemove one or more members from a set.
SISMEMBER key memberCheck if a member exists in the set.
SCARD keyGet the number of members.

Sorted Set (ZSet) Commands

CommandDescription
ZADD key score memberAdd a member with a score.
ZRANGE key start stopGet members by index range.
ZRANGEBYSCORE key min maxGet members by score range.
ZREM key memberRemove member from sorted set.
ZCARD keyGet number of members.

Pub/Sub Commands

CommandDescription
PUBLISH channel messagePost a message to a channel.
SUBSCRIBE channelSubscribe to a channel.
UNSUBSCRIBE channelUnsubscribe from a channel.

Server/Utility Commands

CommandDescription
PINGTest connection.
INFOGet information about the server.
FLUSHALLDelete all keys in all databases.
FLUSHDBDelete all keys in the current DB.
MONITORSee all requests received by the server in real time.