2. The typical SQL/NoSQL breakdown
SQL NoSQL
Single machine Multi-machine / Distributed
Non-relational, references
Relational
possible
Key-value, column-store,
Tables
document store
On disk storage + cache. On disk storage + cache.
ACID BASE
(Atomicity, Consistency, (Basically available, Soft state,
Isolation, Durability) Eventual consistency
3. So what is Redis?
Redis is often called a data structure server.
That is, a database that hosts a set of handy data
structures and extremely useful operations on said
structures.
4. Where does Redis fit in?
Redis NoSQL
Single machine, for now. Multi-machine / Distributed
Non-relational, references
Non-relational
possible
Key-value, column store,
Key-value+++
document store
In memory + disk persistence On disk storage + cache.
BASE
RDB dump. AOF. Or both. (Basically available, Soft state,
Eventual consistency)
5. Introducing Redis into your
production environment.
• Step 1: Find one cool use case for Redis.
• Step 2: Implement and deploy
• Step 3: Find 5 other ways where Redis gives your
app/company a unique advantage.
At YCharts, we use Redis in 6 distinct,
unrelated ways.
6. Data structures
• Key/value
• Lists
• Sets
• Sorted Set
• Hashes
• Pub/sub
7. Key/value
Functionality
• Basic set/get
• Keys can expire or not
• Atomic increment/decrement
Use cases
• Store sparse/one off data: We use it store global site
settings that we wan’t to change on the fly.
• Cache backends: People use it as memcached
replacement, or to save user sessions.
• Really fast, hit counters. Think logging, monitoring,
etc.
8. Lists
Functionality
• Atomic push/pop
• Set/get by index.
• Sort.
Use cases
• We use it as a queue backend. See hotqueue or
celery.
9. Sets
Functionality
• Add/remove.
• Intersect, union, intersect + store, union + store.
• Sort.
Use cases
• We use it to intersects lists of stocks for screening
functionality of our site.
• Good for anything else sets might be used for
normally.
10. Sorted sets
Functionality
• Add/remove/get rank by score.
• Get/remove range of members, by score or reversed
score.
• Union/intersect.
Use cases
• Autocompleters that sort by arbitrary metric. We use
them for fast autocompleter that sorts by company
market cap.
• Really fast range queries. We use it for filtering
metrics on our stock screener.
• Leaderboards for games.
11. Hashes
Functionality
• Set/delete field of hash.
• Set/get multiple fields of hash.
• Increment field.
Use cases
• Tabular or column oriented data.
• We use it to store output of various site usage
reports. Also use it, in essence, as key space for
autocompleter.
12. Pub/sub
Functionality
• Multiple clients can listen for messages published on
a named channel
Use cases
• Streaming / real-time data.
• Stock quotes: One channel per stock symbol ...
multiple browser client listeners. We will use it soon
for this!
• Alerts: One channel / user.
13. Other cool stuff
• Transactions. Atomic execution of multiple
commands.
• Variadic functions. Lots of operations, for examples
Adding a member to a set or list, have versions
where you can add multiple items at once.
• Pipelining. To avoid constant network back/forth,
commands in Redis can be grouped together and
results gotten back in one response. Basically can
fake variadic behavior w/o having actual variadic
functions.
14. Deployment notes
• Most importantly: Redis is very fast and stable.
• Compile from source. Code too fast to use OS
packaged versions.
• Remember it’s a memory DB, so must have as much
memory as data you’re going to hold.
• It’s fast out of the box, tuning is more command
level then system level.
• Most important system setting is level of data
persistence.
• To optimize, make sure you are using variadic
functionality, and where not available, pipelining.
• Replication is an option for data durability.
15. The future
• Redis 2.6. Lua scripting for advanced operations.
• Redis-cluster. Multi-machine / distributed Redis.
Being (very) actively developed.