Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Redis: An introduction

Introduction about Redis data type and use cases

  • Be the first to comment

Redis: An introduction

  1. 1. An introduction March 2014 – Septeni Technology
  2. 2. 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,, engineyard...
  3. 3. 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
  4. 4. 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.
  5. 5. 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.
  6. 6. 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
  7. 7. Hashes • Hash tables as values • Think of an object store with atomic access to object • Members
  8. 8. 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..
  9. 9. Common Web Use Cases Solved in Redis
  10. 10. Show latest items listings in your home page This is a live in-memory cache and is very fast. LPUSH is used to insert a content ID at the head of the list stored at a key. LTRIM is used to limit the number of items in the list to 5000. If the user needs to page beyond this cache only then are they sent to the database.
  11. 11. Leaderboards and related problems A leader board is a set sorted by score. The ZADD commands implements this directly and the ZREVRANGE command can be used to get the top 100 users by score and ZRANK can be used to get a users rank. Very direct and easy.
  12. 12. Counting stuff Keeping stats of all kinds is common, say you want to know when to block an IP addresss. The INCRBY command makes it easy to atomically keep counters; GETSET to atomically clear the counter; the expire attribute can be used to tell when an key should be deleted.
  13. 13. Caching
  14. 14. Discussion
  15. 15. Thank you.