name: empty layout: true --- name: zenslide layout: true .hashtag[#zenluca3m] {{content}} --- class: center, middle background-image: url(images/logo_zencoders-blur.png) # Redis intro Luca Marturana Software Engineer @ A-Tono .footer-left[Catania] .footer-right[04/06/2014] --- # Agenda 1. What's Redis 2. Paradigm 4. Examples 5. Real use cases 6. Conclusions --- # What's Redis [Redis](http://redis.io) is a key-value database server. It stores all our data in memory. You may say, it's a cache! But it's not true. Redis is a **persistent** store. --- # RAM tradeoffs 1. Same speed for reads and writes 2. Read/write latency is negligible 3. When process ends, everything is lost --- # Persistence 1. Every second it writes an append-only file with last write commands 2. Every N writes in M time, it makes a snapshot of all db to disk --- # Paradigm: key value ``` > SET foo bar OK > GET foo "bar" > ``` ??? Open a redis shell and show something --- # Paradigm: numbers ``` > SET number 0 OK > INCR number (integer) 1 > INCR number (integer) 2 > ``` --- # Paradigm: sets ``` > SADD myset value1 value2 (integer) 2 > SISMEMBER myset value2 (integer) 1 > SMEMBERS myset 1) "value1" 2) "value2" ``` --- # Paradigm: other * Lists * Hashes * Sorted sets * HyperLogLog * Publish/Subscribe --- # Usages 1. Task queues 2. Realtime analitics 3. Data with high time-locality 4. Cache --- # Task queue .center.middle[] --- # Task queue Producer ``` LPUSH queue my_amazing_task ``` -- Consumer ``` BRPOP queue 0 ``` --- # Access counter ``` SET access_count 0 EX 60 NX INCR access_count ``` On **access_count** key you will find always all access per minute. --- # Real world usages * Twitter uses it to store last timeline for each user * Pinterest uses Redis to store following/followers graph * A-Tono uses it to store transactions and configurations of its SMS gateway --- # Conclusions Redis is a very interesting storage option. It ensures high performance and persistence of data in a unique way from all other databases. --- template: empty class: the_end --- # Contacts Mail: [lucamarturana@gmail.com](mailto:lucamarturana@gmail.com) Twitter: [@luca3m](http://twitter.com/luca3m) Github: [luca3m](http://github.com/luca3m) Blog: [luca3m.me](http://luca3m.me)