Redis Cheat Sheet

In Redis

Redis is an open-source, in-memory data structure store that is used as a database, cache, and message broker. It is designed to be fast, scalable, and reliable, making it a popular choice for many applications.

Redis is a key-value store, which means that data is stored as a key-value pair. The keys are unique identifiers that are used to retrieve the corresponding values. Redis supports a wide range of data types, including strings, hashes, lists, sets, and sorted sets.

Cheat Sheet

CommandDescription
SET key valueSet the value of a key
GET keyGet the value of a key
DEL keyDelete a key
EXPIRE key secondsSet a key’s time to live in seconds
TTL keyGet the remaining time to live of a key
INCR keyIncrement the integer value of a key by one
DECR keyDecrement the integer value of a key by one
INCRBY key incrementIncrement the integer value of a key by a specified amount
DECRBY key decrementDecrement the integer value of a key by a specified amount
APPEND key valueAppend a value to a key
STRLEN keyGet the length of the value of a key
LPUSH key valueInsert a value at the beginning of a list
RPUSH key valueInsert a value at the end of a list
LPOP keyRemove and get the first element in a list
RPOP keyRemove and get the last element in a list
LINDEX key indexGet an element from a list by its index
LLEN keyGet the length of a list
SADD key memberAdd a member to a set
SREM key memberRemove a member from a set
SMEMBERS keyGet all the members in a set
SCARD keyGet the number of members in a set
SISMEMBER key memberCheck if a member is in a set
ZADD key score memberAdd a member to a sorted set with a score
ZREM key memberRemove a member from a sorted set
ZRANGE key start stopGet a range of members from a sorted set by their index
ZRANGEBYSCORE key min maxGet a range of members from a sorted set by their score
ZCARD keyGet the number of members in a sorted set
ZSCORE key memberGet the score of a member in a sorted set
HSET key field valueSet the value of a field in a hash
HGET key fieldGet the value of a field in a hash
HDEL key fieldDelete a field in a hash
HGETALL keyGet all the fields and values in a hash
HLEN keyGet the number of fields in a hash
PINGPing the server
FLUSHDBDelete all the keys in the current database
SELECT indexSelect the database with the specified index
INFOGet information and statistics about the server
QUITClose the connection to the server

Reference: Redis Commands