How to install and use Redis with Ruby

Ruby posted 11 months ago by christian

Redis and redis-rb example:

   1  git clone git://github.com/ezmobius/redis-rb.git
   2  cd redis-rb/
   3  rake redis:install
   4  rake dtach:install
   5  rake redis:start &
   6  rake install
   7  
   8  cat <<EOF >>test.rb
   9  require 'rubygems'
  10  require 'redis'
  11  
  12  r = Redis.new
  13  
  14  r.delete('foo')
  15  
  16  p'set foo to "bar"'
  17  r['foo'] = 'bar'
  18  
  19  p 'value of foo'
  20  p r['foo']
  21  EOF
  22  
  23  ruby test.rb

If Redis is not started Ruby will exit at Redis.new for some reason without saying anything.

Tagged redis, ruby, key-value, database, cat