• Sort of.
– “A Better Memcached replacement”
– Has native list and set operations
– Non-volatile – periodic snapshots saved to disk
– Pub/sub and notifications (new)
Redis Backgrounder
• Creator / maintainer: Salvatore Sanfilippo
– Supported by VMWare, BSD licensed
• http://code.google.com/p/redis/
Why Use Redis?
• It’s fast.
– Non-blocking I/O
– 100k+ sets/gets per second (on entry-level hardware)
• It scales.
– Use it on a single VPS or …
– Supports replication across several servers
• Getting started is simple.
– Complements existing (database) storage
– Use it for caching
– Use it for queueing
In-Memory
• Entire dataset must fit in RAM
• Virtual memory – Available in Redis 2.0
– Allows infrequently access keys to be saved to disk
– Enable it in redis.conf
Try It
• Install a Redis server on your system
– git clone git://github.com/antirez/redis.git
– cd redis
– make;
– ./redis-server
• Full reference
– http://code.google.com/p/redis/wiki/CommandReference
Use it with Rails!
• Session storage: REDIS-SESSION-STORE gem
– store session data + expire
def self.perform(item_id)
item = Item.find(item_id)
item.archive
end
end
Resque.enqueue(ArchiveJob, @item.id)
Resque: Sinatra Web UI
Resque: Extensions
• quirkey/resque-status
– Provides simple progress tracking for jobs
• zapnap/resque_mailer
– Asynchronous email delivery with ActionMailer
• bvandenbos/resque-scheduler
– Lightweight job scheduling
A/B Testing with Vanity (Uses Redis)
• http://vanity.labnotes.org/
Example Experiment
A Vanity “Experiment”
ab_test "Price options" do
description ”Which is the best price?”
alternatives 19, 25, 29 metrics :signup
end
In Your View…
<h2>Get started for only $<%= ab_test :price_options %> a
month!</h2>
Track Conversions
class SignupController < ApplicationController
def signup
@account = Account.new(params[:account])
if @account.save
track! :signup
redirect_to @acccount
else
render action: :offer
end
end
end
Check Reports
• vanity report --output vanity.html
http://mogotest.com
• We Use Redis for many things:
– Resque / Job queue
– Vanity / Experiment data
– Storing test run job counts
– Model data caching
– Document caching
– View / fragment caches
– Storing aggregated statistics
– User session storage
• But remember: It’s not a replacement for SQL!
More Information
• http://code.google.com/p/redis/
• http://retwis.antirez.com/
• http://rubygems.org/gems/redis
• http://github.com/defunkt/resque
• http://vanity.labnotes.org/