1. Redis
Installing
Basics
Data structures
Pseudo Multi Key Queries
References and Indexes
Round Trips and Pipelining
Transactions
Keys Anti pattern, Use SCAN
Expire, Pub-Sub
Monitor, Sort
Administration
A few commands
Big O
Reference
2. iNSTALLING
• Download redis-2.8.7.tar.gz, untar
• $ make $ make test $ cd src
• $ redis-server #server accepts connections on port6379
• $ redis-cli
• $$ info
• $ redis-benchmark
3. basics
• In-memory persistent key-value store 5 data structures
• $select 1 # many databases
• $ set users:leto '{"name": "leto", "planet": "dune", "likes": ["spice"]}’ #
Every data struct has key eg users:leto
• $ get users:leto # Values are arbitrary byte arrays that Redis doesn’t
care about
4. Data Structures
• Strings $strlen $getrange $append
• Hashes $hset users:goku powerlevel 9000
• Lists $ lpush newusers goku
• Sets $sadd friends:leto ghanima paul chani jessica
• Sortd Sets $ zadd friends:duncan 70 ghanima 95 paul 95 chani 75
jessica 1 vladimir
6. References and Indexes
• $sadd friends:leto ghanima paul chani jessica
• $sadd friends_of:chani leto paul
• # having to manually deal with references in Redis is
unfortunate.
7. Round Trips and Pipelining
• #Redis also supports pipelining. Normally when a
client sends a request to Redis it waits for the reply
before sending the next request. With pipelining you
can send a number of requests without waiting for
their responses.
9. Keys Anti pattern, Use
SCAN
• $ keys bug:1233:*
• #command takes a pattern and finds all the matching keys
• #Should never be used in production code. Linear scan through all the
keys.
• Better:
• $hset bugs:1233 1 '{"id":1, "account": 1233, "subject": "..."}’
• $hset bugs:1233 2 '{"id":2, "account": 1233, "subject": "..."}’
• $ scan 0 match bugs:* count 20 $ hscan $sscan $zscan