2. WHAT IS REDIS?
- Key/Value Store, also referred to as a “data structure
server” for more advanced data structures
- Robust set of features, as well as commands to perform
operations
- In-Memory Datastore, can be persisted to Disk
- Written in C (no dependencies), created by Salvatore
Sanfilippo. Hired/sponsored by VMWare to work on Redis
full-time.
3. REDIS - DATA
STRUCTURE SERVER
- Data types – building blocks:
- Strings: get/set keyname “value”
- Lists: lpush/rpush keyname “value”
- Linked lists (other ops: pop, range, index)
- Think stack
- Hashes: hset/hget hashname keyname “value”
- Think Java hashmap
- Efficient for storing values
- Sets: sadd setname “value”
- Adds unordered, unique values
- Ops: intersection, diff, union
- Sorted Sets: zadd setname 1 (score) “value”
- Ordered, scores can be used for range queries
4. REDIS FEATURES
- All operations are atomic
- Single-threaded
- Example: incr/decr key (i.e. counter)
- Transactions possible
- Execute commands in a single step
- Pub/Sub mechanism
- Many clients/programming lang bindings
- Ruby, Python, Java, Lua, C, Perl, Node.js, Scala, etc.
- Replication
- master/slave config – redundancy
- Clustering
- In an upcoming release in early 2012(?)
- Current clustering solutions in community (Craigslist)
5. IN-MEMORY/PERSIST
TO DISK
- In-memory: constraints can be your RAM in a single-
server instance. With clustering, you could partition data
across multiple nodes, use consistent hashing. See
Craigslist implementation ->
http://blog.zawodny.com/2011/02/26/redis-sharding-at-
craigslist/
- Persisting to disk
- 2 modes: snapshots and append-only file (AOF)
- Snapshots = less durable, potential for data loss
- AOF = more durable (via journaling), can rewrite in the
case of a server going down