Redis Tutorial
http://try.redis.io
Key-Value
SET
SET server:name "fido"
GET
GET server:name
INCR
SET connections 10
INCR connections
DEL
DEL connections
EXPR
SET resource:lock "Redis Demo 1"
EXPIRE resource:lock 120
TTL resource:lock
List
RPUSH
RPUSH friends "Alice"
RPUSH friends "Bob"
LPUSH
LPUSH friends "Sam"
LRANGE
LRANGE friends 0 -1
LRANGE friends 1 2
A value of -1 for the second parameter means to retrieve elements until the end of the list.
LLEN
LLEN friends
LPOP
LPOP friends
RPOP
RPOP friends
Set
SADD
SADD superpowers "flight"
SREM
SREM superpowers "reflexes"
SISMEMBER
SISMEMBER
tests if the given value is in the set.
SISMEMBER superpowers "flight"
SMEMBERS
SMEMBERS
returns a list of all the members of this set.
SMEMBERS superpowers
SUNION
SUNION
combines two or more sets and returns the list of all elements.
Sorted Set
ZADD
ZADD hackers 1940 "Alan Kay"
ZADD hackers 1906 "Grace Hopper"
ZADD hackers 1953 "Richard Stallman"
ZADD hackers 1965 "Yukihiro Matsumoto"
ZADD hackers 1916 "Claude Shannon"
ZADD hackers 1969 "Linus Torvalds"
ZADD hackers 1957 "Sophie Wilson"
ZADD hackers 1912 "Alan Turing"
ZRANGE
ZRANGE hackers 2 4
Hash
HSET
HSET user:1000 name "John Smith"
HSET user:1000 email "john.smith@example.com"
HSET user:1000 password "s3cret"
HGET
HGET user:1001 name
HGETALL
HGETALL user:1000
HMSET
HMSET user:1001 name "Mary Jones" password "hidden" email "mjones@example.com"