Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Redis – Optimized for Joy

Redis – Optimized for Joy

Avatar for Aaron Edmonds

Aaron Edmonds

August 02, 2013

Other Decks in Technology

Transcript

  1. What is Redis? “Redis is an open source, BSD licensed,

    advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.” Created by Salvatore Sanfilippo (aka antirez) Wednesday, August 7, 13
  2. The Redis Manifesto 1: A DSL for Abstract Data Types

    2: Serve data from memory 3: Fundamental data structures and API 4: Code is like a poem 5: Fight against complexity 6: Two levels of API 7: Optimize for joy Wednesday, August 7, 13
  3. Features • Blocking queue • Publish / Subscribe messaging •

    Single-threaded • Supports Pipelining (multiple command without waiting for reply in between) • Supports Master-Slave replication • Transactional grouping of commands • Lua scripting • Redis Sentinel for monitoring • Notification system • Automatic failover • Client configuration server • Slow log • In memory log of responses over specified time (in microseconds) • Built-in benchmarking tool for configuration testing Wednesday, August 7, 13
  4. Strings • Binary safe (any kind of data) • Hold

    up to 512 MB • 22 commands available • SET / GET • STRLEN • INCR / INCRBY / INCRBYFLOAT • SETRANGE / GETRANGE Wednesday, August 7, 13
  5. Hashes • Mapping between string fields and string values •

    Store up to 2^32 - 1 (4,294,967,295) key value pairs • 13 commands available • HSET / HGET / HDEL / HGETALL • HLEN / HKEYS / HVALS • HEXISTS Wednesday, August 7, 13
  6. Lists • List of strings sorted by insertion order •

    Store up to 2^32 - 1 (4,294,967,295) values in the list • Can be used for queueing service • 17 commands available • LSET / LINDEX / LINSERT / LREM • LPUSH / LPOP / LTRIM • BRPOP / BLPOP / BRPOPLPUSH Wednesday, August 7, 13
  7. Sets • Unordered collection of unique strings • Store up

    to 2^32 - 1 (4,294,967,295) values in the list • 14 commands available • SADD / SREM • SMEMBERS / SPOP / SMOVE / SCARD / SRANDMEMBER • SDIFF / SDIFFSTORE / SUNION / SUNIONSTORE / SINTER / SINTERSTORE Wednesday, August 7, 13
  8. Sorted Sets • Unique collection of strings but each value

    has an associated score to determine order • 16 commands available • ZADD / ZREM • ZRANK / ZSCORE / ZREVRANK / ZREMRANGEBYRANK Wednesday, August 7, 13
  9. Available Clients • ActionScript • C • C# • C++

    • Clojure • D • Dart • emacs lisp • Erlang • Fancy • Go • Haskell • haXe • Io • Java • Lua • Node.js • Objective-C • Perl • PHP • Pure Data • Python • Ruby • Scala • Scheme • Smalltalk • Tcl Wednesday, August 7, 13
  10. craigslist • Used with many other data stores • MySQL,

    Memcache, MongoDB, Sphinx, Filesystem • Primary repository of posting activity metadata used in analysis tasks • High usage of Sorted Sets • Replication across 2 data centers Wednesday, August 7, 13
  11. Instagram (2012) • Redis powers... • Main feed • Activity

    feed • Sessions • Runs on several Quadrupal Extra-Large Memory instances (68.4GB of RAM) • Redis Faina https://github.com/Instagram/redis-faina • Leverages Redis’ MONITOR command to collect data and analyze (written in Python) Wednesday, August 7, 13
  12. github https://github.com/blog/542-introducing-resque • Resque https://github.com/resque/resque • Warming caches • Counting

    disk usage • Building tarballs • Firing off web hooks • Creating events in the db and pre- caching them • Building graphs • Deleting users module GitHub module Config def self.[](key) $redis.get("gh:cfg:#{key}") end def self.[]=(key, value) $redis.set("gh:cfg:#{key}", value) end end end Also, configuration storage Wednesday, August 7, 13
  13. Tips • Check out http://redis.io for great documentation • Use

    hashes instead of multiple keys for more efficient storage • Make sure you plan out your memory for your server accordingly • If you are building a URL shortener and you want to use QR codes... Wednesday, August 7, 13