redis: an introduction
TRANSCRIPT
![Page 2: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/2.jpg)
Over view
• Memcache-ish in-memory key/value store
• But values are complex data types:o blobs
o lists
o sets
o sorted sets
o hash tables
• And it has persistence.
• Open source; very helpful and friendly community.
• Used in the real world: pinterest, github, craigslist, bit.ly, engineyard...
![Page 3: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/3.jpg)
Key Features and Cool Stuff
• Speed
• Master/Slave Replication
• All data is eventually persistent
• Handles huge workloads easily
• Variety of Supported Languages
• Support for atomic operations, transactions
• Has pub/sub functionality
• Sharding
![Page 4: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/4.jpg)
List operations
• Lists are your ordinary linked lists.
• You can push and pop at both sides, extract range, resize..
• Random access
• BLPOP: Blocking POP - wait until a list has elements and pop
them. Useful for realtime stuff.
![Page 5: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/5.jpg)
Set operations
• Sets are an unordered collection of Strings
• Sets can be intersected/diffed /union'ed server side.
• Can be useful as keys when building complex schemata.
![Page 6: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/6.jpg)
Sorted Sets• Same as sets, but with score per element
• Ranked ranges, aggregation of scores on INTERSECT
• Can be used as ordered keys in complex schemata
• Think timestamps, inverted index, geohashing, ip ranges
![Page 7: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/7.jpg)
Hashes
• Hash tables as values
• Think of an object store with atomic access to object
• Members
![Page 8: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/8.jpg)
PubSub - Publish/Subscribe
• Clients can subscribe to channels or patterns and receive
• Notifications when messages are sent to channels.
• Use cases: chats, notifycation, real-time applications..
![Page 9: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/9.jpg)
Common Web Use Cases Solved in Redis
![Page 10: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/10.jpg)
Show latest items listings in your home page
This is a live in-memory cache and is very fast. LPUSH isused to insert a content ID at the head of the list storedat a key. LTRIM is used to limit the number of items inthe list to 5000. If the user needs to page beyond thiscache only then are they sent to the database.
![Page 11: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/11.jpg)
Leaderboards and related problems
A leader board is a set sorted by score. The ZADDcommands implements this directly and theZREVRANGE command can be used to get the top 100users by score and ZRANK can be used to get a usersrank. Very direct and easy.
![Page 12: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/12.jpg)
Counting stuff
Keeping stats of all kinds iscommon, say you want to knowwhen to block an IP addresss. TheINCRBY command makes it easy toatomically keep counters; GETSETto atomically clear the counter; theexpire attribute can be used to tellwhen an key should be deleted.
![Page 13: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/13.jpg)
Caching
![Page 14: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/14.jpg)
Discussion
![Page 15: Redis: An introduction](https://reader034.vdocuments.net/reader034/viewer/2022052218/559fa7391a28ab395e8b4754/html5/thumbnails/15.jpg)
Thank you.