| home | about me | feed RSS feed

Been hearing good things about redis.

Let's try it out per Simon Willison's instructions. (Aside: antirez is Salvatore Sanfilippo, open-source programmer extraordinaire and creator of redis.)

git clone git://github.com/antirez/redis
cd redis
make
cd src
./redis-server

Then in another terminal window you can interact with the now-running redis server.

./redis-cli
set foo bar
get foo

Which should go like this:

$ ./redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

If you're not on a POSIX system take redis for a spin on-line.

I also wanted to try driving redis through a programming language. Ohm, an "object-hash mapping library for Redis", looks interesting...

sudo gem install ohm

That seemed to go well:

$ sudo gem install ohm
[sudo] password for adam: 
Successfully installed redis-2.0.10
Successfully installed ohm-0.0.38
2 gems installed
Installing ri documentation for redis-2.0.10...
Installing ri documentation for ohm-0.0.38...
Installing RDoc documentation for redis-2.0.10...
Installing RDoc documentation for ohm-0.0.38...

I added the following to .bashrc to get ruby to load rubygems on startup. It'll be nice when this is no longer needed, but it's not a huge inconvenience for now.

export RUBYOPT=rubygems

When trying it out I got this noise:

irb(main):007:0> require "ohm"
WARNING: using the built-in Timeout class which is known to have issues when used for opening connections. Install the SystemTimer gem if you want to make sure the Redis client will not hang.
=> true

Whatever.

sudo gem install SystemTimer

Which led to another error:

`require’: no such file to load — mkmf (LoadError)

Al Hoang explains that this can be fixed by installing ruby1.8-dev:

sudo aptitude install ruby1.8-dev

So finally having all that working we're ready to go, right? Not so fast...

irb(main):009:0> Ohm.connect
=> []
irb(main):010:0> Ohm.redis.set "Foo", "Bar"
RuntimeError: -ERR unknown command

What now!?
Turns out I had an older version of redis installed.

sudo aptitude remove redis-server

Upon removal of the older version—which happened to be installed via package manager—all was well.

$ irb
irb(main):001:0> require "ohm"
=> true
irb(main):002:0> Ohm.connect
=> []
irb(main):003:0> Ohm.redis.set "foo", "bar"
=> "OK"
irb(main):004:0> Ohm.redis.get "foo"
=> "bar"

Happy key-value storing!

created: 2010-09-26 | updated: 2010-09-26


comments:
on 2010-10-05 Senthil wrote:

I have been hearing about the redis for a while now. Wonder is it so much in news? What is exact advantages or people see the benefit in using redis for? TIA.

on 2010-10-06 adam wrote:

Hi Senthil, thank you for your comment. In hindsight I should have linked to a collection of Redis use-cases in the original post. I hope those examples give you some idea of how you might be able to leverage Redis in your own projects :-) Best regards.

Comments are now closed for this post.