Taking a break from Erlang momentarily to install Redis. Redis is a database that specializes in storing key-value pairs.
Getting Redis
1) Go to the Redis downloads page and download the latest tarball source. http://redis.io/download I'm using version 2.8.6, which is the latest stable version as of today's date.
2) Unpack Redis:
> gunzip redis-2.8.6.tar.gz
> tar -xf redis-2.8.6.tar
3) Step into the redis directory and build the source:
> cd redis-2.8.6
> make
> sudo make install
At this point I'd like to give props to the Redis developers. To have a Makefile that "just works" is phenomenal! So far I'm really liking Redis- if only for the ease of building/installation.
Running Redis
I should also note at this point- similar to how yaws requires an instance to be running either as daemon or interactive, redis is the same way. To run the server in an interactive mode:
1) Open a Terminal.
2) Type:
> redis-server
You should see some decorative text. If you haven't done this step you may get an error message such as:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Not good. So to avoid this, run redis-server and be happy.
Erlang Tie-In
Introducing eredis, by Github user wooga. This is some cool stuff- you can use the instructions at https://github.com/wooga/eredis to connect to the redis server from your Erlang application! The instructions are good so I won't repeat them here. Something interesting to note is that the function eredis:q takes two parameters: a connection to the redis database and a list. The list is cool because it's the string components of the query. If you are going to set some data:
eredis:q( Connection, [ "SET", "mykey", "Hello World" ] ).
It doesn't get much simpler. The return from this function is a tuple where the first element should be "ok" or whatever the resulting status was. The second argument will be whatever the values returned are.
Conclusion
Being unsure about databases I really like redis. It's very simple- just key/value. Connecting to it couldn't be easier. Running it couldn't be easier. I'm thinking that the purpose of this post is to try and get the word out about this. If I run into any problems later I'll come back to do an addendum.
No comments:
Post a Comment