Who am I?
● A guy who does a lot of stuff with Redis and Python
○ Book:
■ Redis in Action http://manning.com/carlson
■ Read for free http://bit.ly/ria-free
○ Libraries: https://github.com/josiahcarlson
■ rom, RPQueue, lua_call, ...
○ Mailing list: https://groups.google.com/forum/#!forum/redis-db
○ Blog: dr-josiah.com
○ Twitter: @dr_josiah
What is Redis?
● In-memory non-relational key -> data structure server
○ integers, floats, strings, bitmaps, hyperloglogs, lists, sets, hashes, sorted sets(,
geoindex)
○ Plus pubsub, key change notifications, ...
● Optional on-disk persistence
● Optional master/slave replication
○ Optional sentinel for high-availability/failover
● Optional separate clustering mode as of April 2015
● Server-side Lua scripts (like stored procedures, only easier)
● Third party client-sharding via clients or Twemproxy/Nutcracker
Use-case 1: Distributed locking
● 10-100x faster than Zookeeper by default
○ can be tuned for the same reliability
● Multiple locks at the same time
○ job input/output coordination
■ MySQL DDL/truncate operations - locking outside can save your bacon
○ locks that “never” time out
○ locks that time out, or require refreshing
○ counting semaphores for multiple lock holders
Use-case 2: Analytics
● Stop counting after the fact
○ Handle 100-200k events/second without pipelining/batching
○ Handle 1M+ events/second with pipelining/batching
■ Send one batched call at the end of the request
● Use a Lua script for hierarchical counters
● As simple as a counter, or with a little work min/max/avg/stddev
● Minor modifications get you rate limiting
○ Login, API, bandwidth utilization, …
○ With locking (and counting semaphores), can limit outgoing API usage
○ Pick your semantic: counters, sliding window, leaky bucket, or something else
Use-case 3: Web cookies
● No more:
○ encrypting/signing your cookies badly (still need to make them https-only)
○ running into 4k cookie limits
○ slow mobile requests due to overweight cookies
● Easily structured cookie data storage
○ Shopping carts
○ Last X pages visited per user
■ Real-time analytics/trend analysis over recent pages, where to go, what to buy, etc. (people
who viewed this item bought item X some Y% of the time)
○ A listing of recent logins per user, with cookie deletion
Use-case 4: Queues/message passing
● Libraries in most languages
○ Use an off-the-shelf library, or write one that fits your required semantics (0/1 or 1+)
● Prioritization, delayed, cron-scheduled, every X seconds, etc.
● Blocking queues with listeners listening on multiple queues
● Broadcasting with pubsub
● If you like Redis, but want a queue
○ Salvatore has written Disque, a 1+ queue system
Use-case 5: Anything you’re using Memcached for
● Memcached does strings and ints
● Redis does
○ integers, floats, strings, bitmaps, hyperloglogs, lists, sets, hashes, sorted sets(,
geoindex)
○ pubsub (generally, and keyspace changes)
○ optimistic locking and basic transactions with WATCH/MULTI/EXEC
○ Lua scripting
■ … a literally uncountable number of things that Memcached can’t do
...and many more
● DB row caching
● Web page caching
● Autocomplete
● Dynamically updated toplists for
games
● Generalized voting/ranking (Reddit,
Hacker News, etc.)
● Unique visitor counts on hourly,
daily, weekly, and/or monthly basis
● Custom search engines/ad targeting
● Rate-limited geo notifications
● As a general data store (various
libraries, some with pseudo-relational
layer)