Red Is
Red Is
0]
starting the server cd redis; ./redis-server
running the client ./redis-cli <command>
commands
Test if specified key exists.
exists key Return: 1 if exists, 0 if not
Remove the specified keys.
del key1 key2 ... keyN Return: integer > 0 if keys removed, 0 if none of the keys existed
Return the type of the value stored at key, as a string.
type key Return: "none", "string", "list", "set"
Return all keys matching pattern. Ex: keys h*llo, keys h?llo, keys h[aeo]llo
keys pattern Return: bulk reply string with keys separated by spaces
Return a randomly-selected key from the current database.
randomkey Return: the selected key, or empty string if database is empty
generic commands for all types
set key value Sets the value of key to the string value; setnx will not overwrite an existing value.
setnx key value Return: 1 if OK, 0 if error
Gets the value of key.
get key Return: string value if OK, "nil" if key does not exist
commands for strings
Atomically sets the value of key to the string value and returns old value of key.
getset key value Return: value of key prior to the new value being set ("nil" if key did not exist)
Gets the values of all specified keys.
mget key1 key2 ... keyN Return: multi-bulk reply of all values, with "nil" for any keys that do not exist
mset key1 value1 ... keyN valueN Sets the values of the keys to the string values; msetnx will not overwrite existing
msetnx key1 value1 ... keyN valueN values if any key exists. Return: 1 if all keys were set, 0 if none were set
sinter key1 key2...keyN Returns the members resulting from intersection of sets specified. sinterstore will
sinterstore dstkey key1...keyN store results in new set and return status code.
sunion key1 key2...keyN Returns the members resulting from union of sets specified. sunionstore will store
sunionstore dstkey key1...keyN results in new set and return status code.
sdiff key1 key2...keyN Returns the members resulting from the difference between the first set and the
sdiffstore dstkey key1...keyN rest. sdiffstore will store results in new set and return status code.
Returns all of the members of set key. This is sinter, for only one set.
smembers key Return: the members
sort key [by pattern] [limit start count] [get pattern] [asc|desc] [alpha] [store dstkey]
Sorts the elements in the list, set, or sorted set at key. Default sort is numeric, ascending. Specifying asc or desc will sort in ascending or
descending order. Specifying alpha will sort alphabetically. limit will return count number of elements beginning at offset start (zero-
based). store will put the results of the sort into a list with key dstkey.
Specifying "by pattern" will sort using the values at keys generated using the pattern. For example, if the list/set being sorted contains the
values 1, 2, 3 then "sort by weight_*" will sort using the values at keys "weight_1", "weight_2", "weight_3".
Specifying "get pattern" will retrieve the values stored at keys generated using the pattern. For example, "get items_*" will return the
values at keys items_1, items_2, items_3 if the list/set being sorted contains the values 1, 2, 3.
REDIS cheatsheet page 3
Adds member to zset key, with specified score.
zadd key score member Return: 1 if added, 0 if element was already a member and score was updated
Removes member from zset key.
zrem key member
commands operating on sorted sets
Saves all databases to disk. Connection requests will not be served during the
save save. Returns OK when complete.
Saves all databases to disk in the background. Redis forks and writes so the
bgsave parent process continues to process connection requests.
Returns integer unix time of last successful save. This can be used following a
lastsave
persistence and control commands
Used to enter commands for debugging. Telnet to redis server then enter
monitor monitor command. Enter quit to end the session.
slaveof host port Makes server the replication slave of the redis server at host/port. The "no one"
slaveof no one form turns off replication, making the server a master.
Authorizes client using the provided password, if redis server is configured with
auth password requirepass. Returns OK or error if password is incorrect.