Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

#Redis Commands

##Generic Commands

  • DEL key [key …] - Delete a key
  • DUMP key - Return a serialized version of value stored at specified key
  • EXISTS key - Determine if a key exists
  • EXPIRE key seconds - Set a key's time to live in seconds
  • EXPIREAT key timestamp - Set expiration for a key as a UNIX timestamp
  • KEYS pattern - Find all keys matching given pattern
  • MIGRATE host port key destination-db timeout - Atomically transfer a key from a Redis instance to another one
  • MOVE key db - Move a key to another database
  • OBJECT subcommand [arguments [arguments …]] - Inspect internals of Redis objects
  • PERSIST key - Remove expiration from a key
  • PEXPIRE key milliseconds - Set a key's time to live in milliseconds
  • PEXPIREAT key milliseconds-timestamp - Set expiration for a key as a UNIX timestamp specified in milliseconds
  • PTTL key - Get time to live for a key in milliseconds
  • RANDOMKEY - Return a random key from keyspace
  • RENAME key newkey - Rename a key
  • RENAMENX key newkey - Rename a key, only if new key does not exist
  • RESTORE key ttl serialized-value - Create a key using provided serialized value, previously obtained using DUMP
  • SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination] - Sort elements in a list, set or sorted set
  • TTL key - Get time to live for a key
  • TYPE key - Determine type stored at key

##String Commands

  • APPEND key value - Append a value to a key
  • BITCOUNT key [start] [end] - Count set bits in a string
  • BITOP operation destkey key [key …] - Perform bitwise operations between strings
  • DECR key - Decrement integer value of a key by one
  • DECRBY key decrement - Decrement integer value of a key by given number
  • GET key - Get value of a key
  • GETBIT key offset - Returns bit value at offset in string value stored at key
  • GETRANGE key start end - Get a substring of string stored at a key
  • GETSET key value - Set string value of a key && return its old value
  • INCR key - Increment integer value of a key by one
  • INCRBY key increment - Increment integer value of a key by given amount
  • INCRBYFLOAT key increment - Increment float value of a key by given amount
  • MGET key [key …] - Get values of all given keys
  • MSET key value [key value …] - Set multiple keys to multiple values 1.0.1
  • MSETNX key value [key value …] - Set multiple keys to multiple values, only if none of keys exist
  • PSETEX key milliseconds value - Set value && expiration in milliseconds of a key
  • SET key value - Set string value of a key
  • SETBIT key offset value - Sets or clears bit at offset in string value stored at key
  • SETEX key seconds value - Set value && expiration of a key
  • SETNX key value - Set value of a key, only if key does not exist
  • SETRANGE key offset value - Overwrite part of a string at key starting at specified offset
  • STRLEN key - Get length of value stored in a key

##List Commands

  • BLPOP key [key ...] timeout - Remove && get first element in a list, or block until one is available
  • BRPOP key [key ...] timeout - Remove && get last element in a list, or block until one is available
  • BRPOPLPUSH source destination timeout - Pop a value from a list, push it to another list && return it; or block until one is available
  • LINDEX key index - Get an element from a list by its index
  • LINSERT key BEFORE|AFTER pivot value - Insert an element before or after another element in a list
  • LLEN key - Get length of a list
  • LPOP key - Remove && get first element in a list
  • LPUSH key value [value …] - Prepend one or multiple values to a list
  • LPUSHX key value - Prepend a value to a list, only if list exists
  • LRANGE key start stop - Get a range of elements from a list
  • LREM key count value - Remove elements from a list
  • LSET key index value - Set value of an element in a list by its index
  • LTRIM key start stop - Trim a list to specified range
  • RPOP key - Remove && get last element in a list
  • RPOPLPUSH source destination - Remove last element in a list, append it to another list && return it
  • RPUSH key value [value …] - Append one or multiple values to a list
  • RPUSHX key value - Append a value to a list, only if list exists

##Set Commands

  • SADD key member [member ...] - Add one or more members to a set
  • SCARD key - Get number of members in a set
  • SDIFF key [key ...] - Subtract multiple sets
  • SDIFFSTORE destination key [key ...] - Subtract multiple sets && store resulting set in a key
  • SINTER key [key ...] - Intersect multiple sets
  • SINTERSTORE destination key [key ...] - Intersect multiple sets && store resulting set in a key
  • SISMEMBER key member - Determine if a given value is a member of a set
  • SMEMBERS key - Get all members in a set
  • SMOVE source destination member - Move a member from one set to another
  • SPOP key - Remove && return a random member from a set
  • SRANDMEMBER key [count] - Get one or multiple random members from a set
  • SREM key member [member ...] - Remove one or more members from a set
  • SUNION key [key ...] - Add multiple sets
  • SUNIONSTORE destination key [key ...] - Add multiple sets && store resulting set in a key

##Sorted-Set Commands

  • ZADD key score member [score] [member] - Add one or more members to a sorted set, or update its score if it already exists
  • ZCARD key - Get number of members in a sorted set
  • ZCOUNT key min max - Count members in a sorted set with scores within given values
  • ZINCRBY key increment member - Increment score of a member in a sorted set
  • ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX] - Intersect multiple sorted sets && store resulting sorted set in a new key
  • ZRANGE key start stop [WITHSCORES] - Return a range of members in a sorted set, by index
  • ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count] - Return a range of members in a sorted set, by score
  • ZRANK key member - Determine index of a member in a sorted set
  • ZREM key member [member ...] - Remove one or more members from a sorted set
  • ZREMRANGEBYRANK key start stop - Remove all members in a sorted set within given indexes
  • ZREMRANGEBYSCORE key min max - Remove all members in a sorted set within given scores
  • ZREVRANGE key start stop [WITHSCORES] - Return a range of members in a sorted set, by index, with scores ordered from high to low
  • ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count] - Return a range of members in a sorted set, by score, with scores ordered from high to low
  • ZREVRANK key member - Determine index of a member in a sorted set, with scores ordered from high to low
  • ZSCORE key member - Get score associated with given member in a sorted set
  • ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX] - Add multiple sorted sets && store resulting sorted set in a new key

##Hash Commands

  • HDEL key field [field ...] - Delete one or more hash fields
  • HEXISTS key field - Determine if a hash field exists
  • HGET key field - Get value of a hash field
  • HGETALL key - Get all fields && values in a hash
  • HINCRBY key field increment - Increment integer value of a hash field by given number
  • HINCRBYFLOAT key field increment - Increment float value of a hash field by given amount
  • HKEYS key - Get all fields in a hash
  • HLEN key - Get number of fields in a hash
  • HMGET key field [field ...] - Get values of all given hash fields
  • HMSET key field value [field value ...] - Set multiple hash fields to multiple values
  • HSET key field value - Set string value of a hash field
  • HSETNX key field value - Set value of a hash field, only if field does not exist
  • HVALS key - Get all values in a hash

##PubSub Commands

  • PSUBSCRIBE pattern [pattern ...] - Listen for messages published to channels matching given patterns
  • PUBLISH channel message - Post a message to a channel
  • PUNSUBSCRIBE [pattern [pattern ...]] - Stop listening for messages posted to channels matching given patterns
  • SUBSCRIBE channel [channel ...] - Listen for messages published to given channels
  • UNSUBSCRIBE [channel [channel ...]] - Stop listening for messages posted to given channels

##Transaction Commands

  • DISCARD - Discard all commands issued after MULTI
  • EXEC - Execute all commands issued after MULTI
  • MULTI - Mark start of a transaction block
  • UNWATCH - Forget about all watched keys
  • WATCH key [key ...] - Watch given keys to determine execution of MULTI/EXEC block

##Connection Commands

  • AUTH password - Authenticate to server
  • ECHO message - Echo given string
  • PING - Ping server
  • QUIT - Close connection
  • SELECT index - Change selected database for current connection

##Server Commands

  • BGREWRITEAOF - Asynchronously rewrite append-only file
  • BGSAVE - Asynchronously save dataset to disk
  • CLIENT KILL ip:port - Kill connection of a client
  • CLIENT LIST - Get list of client connections
  • CONFIG GET parameter - Get value of a configuration parameter
  • CONFIG RESETSTAT - Reset stats returned by INFO
  • CONFIG SET parameter value - Set a configuration parameter to given value
  • DBSIZE - Return number of keys in selected database
  • DEBUG OBJECT key - Get debugging information about a key
  • DEBUG SEGFAULT - Make server crash
  • FLUSHALL - Remove all keys from all databases
  • FLUSHDB - Remove all keys from current database
  • INFO - Get information && statistics about server
  • LASTSAVE - Get UNIX time stamp of last successful save to disk
  • MONITOR - Listen for all requests received by server in real time
  • SAVE - Synchronously save dataset to disk
  • SHUTDOWN [NOSAVE] [SAVE] - Synchronously save dataset to disk && then shut down server
  • SLAVEOF host port - Make server a slave of another instance, or promote it as master
  • SLOWLOG subcommand [argument] - Manages Redis slow queries log
  • SYNC - Internal command used for replication
  • TIME - Return current server time

##Scripting Commands

  • EVAL script numkeys key [key ...] arg [arg ...] - Execute a Lua script server side
  • EVALSHA sha1 numkeys key [key ...] arg [arg ...] - Execute a Lua script server side
  • SCRIPT EXISTS script [script ...] - Check existence of scripts in script cache
  • SCRIPT FLUSH - Remove all scripts from script cache
  • SCRIPT KILL - Kill script currently in execution
  • SCRIPT LOAD script - Load specified Lua script into script cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.