Redis Data Types and Commands Reference

String is a basic data type in Redis where one Key corresponds to one Value. A value of the String type can store up to 512MB of data.
The Redis String data type supports a rich set of operation commands, commonly used String operations are listed as follows:

Command Description
set Set the value for the specified key
get Get the value for the specified key
setnx Set the value of a key only if it does not exist
getrange Return the substring of the string value stored in the key
mset Simultaneously set one or more key-value pairs
setex Associate the value value with the key and set its expiration time to seconds (in seconds)
gebit Get the bit at a specified offset in the string value stored in the key
sebit Set or clear the bit at a specified offset in the string value stored in the key
decr Decrement the numeric value stored as part of the key
decrby Subtract a given decrement from the value associated with the key
strlen Return the length of the string value stored in the key
msetnx Simultaneously set one or more Key-value pairs, but only if all specified keys do not exist
incrby Increment the numeric value stored as part of a key by a given amount
incrbyfloat Add a given floating-point increment to the number stored in the key
setrange Override the string value stored for the given key starting at offset offset with parameter value
psetex Similar to setex, but sets the lifetime of the key in milliseconds rather than seconds as setex does
append If a key exists and is a string, append value to the end of that string
getset Set the value for the given Key to value and return the old value
mget Get (one or more) values of specified keys
incr Increment by 1 the numeric value stored in a key

Hash

Redis Hash is a collection of key-value pairs. The operations supported for Redis Hash lists are listed as follows:

Command Description
hmset Simultaneously set multiple field-value pairs to the hash table key
hmget Get values of all specified fields
hset Set the value for a field in the hash table key to value
hgetall Retrieve all fields and values associated with the specified key from the hash list
hget Get the value stored at a specific field within a hash
hexists Check if a specified field exists in the hash table key
hincrby Increment an integer value of a specified field by increment for the hash table key
hlen Retrieve the number of fields contained in the hash
hdel Delete one or more fields from a hash
hvals Get all values stored within the hash
hincrbyfloat Increment an integer value of a specified field by increment for floating point numbers in the hash table key
hkeys Retrieve all keys contained in the hash
hsetnx Set the value for a specific field within a hash only if that field does not exist

List

Redis List is a simple string list, which is ordered by insertion order. We can add an element to either the head or tail of the list. A list can store up to $2^{31}-1$ elements.

Command Description
lindex Retrieve a member from the list by index
rpush Add one or more values to the end of the list
lrange Get members within a specified range in the list
rpoplpush Remove and return the last element of a list, pushing it onto another list
blpop Block until an element is available; remove and get the first element from the head of the list
brpop Block until an element is available; remove and get the last element from the tail of the list
brpoplpush Remove a value from one end of a list, push it to another list, and return it; block if no elements are present
lrem Remove zero or more occurrences of members from the list
llen Get the length of the list
ltrim Trim a list so that it only contains specified range indices
lpop Block until an element is available; remove and get the first element from the head of the list
lpushx Append one or more values to the beginning of an existing list
linsert Insert a new member before or after another specified member in the list
rpop Remove and return the last element of the list
lset Set the value at index index within the list
lpush Prepend one or more values to an existing list
rpushx Append zero or more values to a non-empty list

Set

Set is an unordered collection of string elements. Sets are implemented using hash tables, so add, delete, and lookup operations all have O(1) complexity. Operations supported by Set include:

Command Description
sunion Return the union of multiple sets
scard Get the number of members in a set
srandmember Return one or more random elements from a set
smembers Retrieve all members of a set
sinter Return the intersection of specified sets
srem Remove zero or more members from a set
smove Move member(s) from one set to another
sadd Add multiple elements to a set
sismember Check if an element is a member of the specified key's set
sdiffstore Return the difference between sets and store it in destination
sdiff Return the difference between sets
sscan Iterate over members of a set
sinterstore Store the intersection of multiple sets into a new key
sunionstore Store the union of all specified sets into a destination key
spop Remove and return an arbitrary member from a set

ZSet

Redis Sorted Set (ZSet) is also a string-based collection, but unlike Sets it allows no duplicate members. Each element has an associated score which is stored as a double value. Redis uses the scores to order elements in ascending or descending order within the sorted set. Operations supported by Redis ZSet include:

Command Description
zrevrank Return the rank of member member in a sorted set, with members ordered from highest to lowest score
zlexcount Count elements within a given lexicographical range in a sorted set
zunionstore Compute the union of one or more sorted sets and store it under a new key
zremrangebyrank Remove all members with scores less than, equal to, or greater than start through stop from a sorted set
zcard Get the number of elements in a sorted set
zrem Remove one or more specified members from a sorted set
zinterstore Compute the intersection of multiple sorted sets and store it under a new key
zrank Return the index (rank) of member member within a sorted set
zincrby Increment the score associated with member by increment in a sorted set
zrangebyscore Retrieve members from a sorted set, where scores are between minimum and maximum inclusive
zrangebylex Return all elements within a given lexicographical range of a sorted set
zscore Get the score associated with member member in a sorted set
zremrangebyscore Remove members from a sorted set, where scores are less than or equal to maximum and greater than minimum
zscan Iterate over elements of a sorted set (including both element values and their respective scores)
zrevrangebyscore Return all members within the specified score range in descending order
zremrangebylex Remove all elements from a given lexicographical range in a sorted set
zrevrange Return all members between start and stop, ordered by their scores (descending)
zrange Retrieve multiple values within the specified index range of a sorted set
zcount Count elements with score greater than or equal to minimum and less than maximum in a sorted set
zadd Add new members, updating existing ones if they already exist

Bitmap

Records data by operating on binary bits. Operations supported by Redis Bitmap include:

Command Description
setbit Set the value at a specified bit offset
getbit Get the value of a specific bit
bitcount Count number of bits in a range that are equal to 1
destkey Perform bitwise operations (AND, OR, NOT, XOR) on bitmap data

HyperLogLog

A probabilistic data structure used for estimating the cardinality of elements within a Set. Operations supported by Redis HyperLogLog include:

Command Description
pfadd Add an element to one or more hyperloglogs
pfcount Return the estimated cardinality for given hyperloglogs
pfmerge Merge multiple hyperloglogs into a single hyperloglog

Geospatial

Used for calculating geographical spatial relationships. Operations supported by this data type include:

Command Description
geohash Return the geohash representation of one or more location elements
geopos Retrieve all locations (longitude and latitude) for given position keys
geodist Calculate distance between two positions
georadius Find members within a certain radius from a specified center point
geoadd Add one or more geographical location elements to the key
georadiusbymember Find all locations that are within a given distance of another member