Redis is an in memory datastore with optional snapshot persistence and replication.
Use the redis-cli command to interact with a local redis server.
> redis-cli 127.0.0.1:6379> help ...
Redis server provides access to multiple databases identified by sequential numbers starting from zero. Each database is a key value store whose keys are binary safe strings and values can be one of strings, lists, sets, sorted sets, maps, streams, and hyper log log estimators.
Databases. A server can host multiple databases
Identified by sequential numbers starting from zero
Each database is a key value store
Keys are binary safe strings
Keys can have expiration time
Values are typed
Value Types. Binary safe string
Can also be interpreted as an integer or a float or a bitmap
List
Ordered list of binary safe strings
Atomic element removal from both ends
Set
Set and sorted set of binary safe strings
Sorted set keeps float score with each element
Hash
A key value map of binary safe strings
Stream
A stream of key value maps of binary safe strings
Individual consumers query entries by timestamp
Consumer groups can cooperate in processing
Hyper Log Log estimator
Opaque type for estimating set cardinality
A database can have an eviction policy, default is no eviction. Alternatives include random and LRU and TTL based policies working across either all keys or keys with expiration set.
The database content snapshot can be periodically written to disk, or an operation log can be written to disk and periodically compacted, or both.
select database to use
swap databases
get number of keys in database
move existing key to another database
delete all keys from all databases
delete all keys from current database
iterate over existign keys
list keys matching glob
get random existing key (but not value)
test existence of a key
copy existing value to another key
move existing value to another key
... if target does not exist
delete a key
... with asynchronous memory reclaim
set relative key expiration time
... in milliseconds
set absolute key expiration time
... in milliseconds
get key expiration time
... in milliseconds
remove key expiration time
serialize value with checksum
... and restore serialized value
set last access time for eviction policies
get key type (string, list, hash, zset, set, stream)
get the value associated with a key
... or only some characters
... and delete the key
... and set key expiration time
set the value associated with a key
... or only some characters
... if target does not exist
... and set the key expiration time
... in milliseconds
... and return the previous value
get values for multiple keys
set values for multiple keys
... if targets do not exist
append new value to the existing value
get the length of the existing value
get single bit
set single bit
count bits that are set
find first bit that is set or reset
perform logical operation between multiple keys
perform get or set or inc on subset of bits
interpret string as integer and increment
... by arbitrary value
interpret string as integer and decrement
... by arbitrary value
interpret string as float and increment or decrement
> redis-cli 127.0.0.1:6379> help @string ... 127.0.0.1:6379> SET somekey somevalue OK 127.0.0.1:6379> GET somekey "somevalue" 127.0.0.1:6379> GETRANGE somekey 3 6 "eval" 127.0.0.1:6379> GETSET somekey anothervalue "somevalue" 127.0.0.1:6379> GETBIT somekey 15 (integer) 0 127.0.0.1:6379> SETBIT somekey 15 1 (integer) 0 127.0.0.1:6379> GET somekey "aoothervalue" 127.0.0.1:6379> INCR somekey (error) ERR value is not an integer or out of range 127.0.0.1:6379> SET somekey 123 OK 127.0.0.1:6379> INCR somekey (integer) 124 127.0.0.1:6379> GET somekey "124" 127.0.0.1:6379> SET somekey ephemeral PX 1 OK 127.0.0.1:6379> GET somekey (nil) ...
iterate over existing fields
list existing fields
get existing values
get random existing field (and value)
test existence of a field
get the number of existing fields
delete a field
get the value of a field
set the value of a field
... if target does not exist
get all fields and values
get multiple fields
set multiple fields
get the length of a field value
interpret field as integer and increment or decrement
interpret field as float and increment or decrement
> redis-cli 127.0.0.1:6379> help @hash ... 127.0.0.1:6379> HSET somekey somefield somevalue (integer) 1 127.0.0.1:6379> HSET somekey anotherfield anothervalue (integer) 1 127.0.0.1:6379> GET somekey (error) WRONGTYPE Operation against a key holding the wrong kind of value 127.0.0.1:6379> HGET somekey somefield "somevalue" 127.0.0.1:6379> HGETALL somekey 1) "somefield" 2) "somevalue" 3) "anotherfield" 4) "anothervalue" 127.0.0.1:6379> HRANDFIELD somekey 1 WITHVALUES 1) "somefield" 2) "somevalue" ...
subscribe to messages from given channels
... with channels given by glob
unsubscribe from given channels
... with channels given by glob
publish a message on a given channel
list channels with subscribers
subscription restricts connection commands to pubsub
publishing does not require prior channel connection
pattern subscription therefore matches continuously
key update notifications available on channels derived from key names
> redis-cli 127.0.0.1:6379> help @pubsub ... 127.0.0.1:6379> SUBSCRIBE somechannel Reading messages... (press Ctrl-C to quit) ...
> redis-cli 127.0.0.1:6379> PUBSUB CHANNELS 1) "somechannel" 127.0.0.1:6379> PUBLISH somechannel somemessage (integer) 1 ...
begin a transaction
commit a transaction
abort a transaction
changes to watched keys label transaction fail only
discard watched keys
results of all operations are collected during the transaction
individual operation failures do not terminate the transaction
> redis-cli 127.0.0.1:6379> help @transactions ... 127.0.0.1:6379> MULTI OK 127.0.0.1:6379(TX)> SET somekey somevalue QUEUED 127.0.0.1:6379(TX)> SET anotherkey anothervalue QUEUED 127.0.0.1:6379(TX)> EXEC 1) OK 2) OK 127.0.0.1:6379> WATCH somekey OK 127.0.0.1:6379> GET somekey "somevalue" 127.0.0.1:6379> MULTI OK 127.0.0.1:6379(TX)> SET anotherkey somevalue QUEUED 127.0.0.1:6379(TX)> EXEC (nil) 127.0.0.1:6379> GET somekey "interference" ...
execute LUA code with arguments
... or execute LUA code from cache
explicitly load LUA code to cache
check presence of LUA code in cache
drop LUA code cache content
script execution is atomic
long running read only scripts can be terminated after timeout
long running read write scripts cannot be terminated other than by shutdown
> redis-cli 127.0.0.1:6379> help @scripting ... 127.0.0.1:6379> SET somekey 123 OK 127.0.0.1:6379> SET anotherkey 456 OK 127.0.0.1:6379> EVAL "return tonumber (redis.call ('GET', KEYS [1])) + tonumber (redis.call ('GET', KEYS [2]))" 2 somekey anotherkey (integer) 579 ...
The redis Website. http://www.redis.io