diff options
| author | Franck Cuny <franck.cuny@gmail.com> | 2013-11-26 10:36:10 -0800 |
|---|---|---|
| committer | Franck Cuny <franck.cuny@gmail.com> | 2013-11-26 10:36:10 -0800 |
| commit | 8ddf2e94df70707b458528a437759b96046d3e01 (patch) | |
| tree | d442818d92d3c9c6f7fcdc92857a1228963849a1 /_posts/2009-12-13-riak-perl-and-kiokudb.md | |
| parent | Don't need to use the IP in the makefile. (diff) | |
| download | lumberjaph-8ddf2e94df70707b458528a437759b96046d3e01.tar.gz | |
Huge update.
Moved all posts from textile to markdown. Updated all the CSS and
styles. Added a new page for the resume.
Diffstat (limited to '')
| -rw-r--r-- | _posts/2009-12-13-riak-perl-and-kiokudb.md (renamed from _posts/2009-12-13-riak-perl-and-kiokudb.textile) | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/_posts/2009-12-13-riak-perl-and-kiokudb.textile b/_posts/2009-12-13-riak-perl-and-kiokudb.md index c0a51de..5065042 100644 --- a/_posts/2009-12-13-riak-perl-and-kiokudb.textile +++ b/_posts/2009-12-13-riak-perl-and-kiokudb.md @@ -1,6 +1,6 @@ --- layout: post -category: perl +summary: In which I write about Riak Perl and KiokuDB. title: Riak, Perl and KiokuDB --- @@ -10,34 +10,34 @@ So Riak is a document based database, it's key value, no sql, REST, and in Erlan One of the nice things with Riak it's that it let you defined the N, R and W value for each operation. This values are: - * N: the number of replicas of each value to store - * R: the number of replicas required to perform a read operation - * W: the number of replicas needed for a write operation +* N: the number of replicas of each value to store +* R: the number of replicas required to perform a read operation +* W: the number of replicas needed for a write operation Riak comes with library for python ruby PHP and even javascript, but not for Perl. As all these libraries are just communicating with Riak via the REST interface, I've <a href="http://github.com/franckcuny/anyevent-riak">started to write one</a> using AnyEvent::HTTP, and <a href="http://github.com/franckcuny/kiokudb-backend-riak">also a backend for KiokuDB</a>. -h3. Installing and using Riak +## Installing and using Riak If you interested in Riak, you can install it easily. First, you will need the Erlang VM. On debian, a simple {% highlight bash %} -sudo aptitude install erlang +% sudo aptitude install erlang {% endhighlight %} install everything you need. Next step is to install Riak: {% highlight bash %} -wget http://hg.basho.com/riak/get/riak-0.6.2.tar.gz -tar xzf riak-0.6.2.tar.gz -cd riak -make -export RIAK=`pwd` +% wget http://hg.basho.com/riak/get/riak-0.6.2.tar.gz +% tar xzf riak-0.6.2.tar.gz +% cd riak +% make +% export RIAK=`pwd` {% endhighlight %} Now, you can start to use it with {% highlight bash %} -./start-fresh config/riak-demo.erlenv +% ./start-fresh config/riak-demo.erlenv {% endhighlight %} or if you want to test it in cluster mode, you can write a configuration like this: @@ -59,10 +59,10 @@ or if you want to test it in cluster mode, you can write a configuration like th {riak_web_logdir, "/tmp/riak_log"}. {% endhighlight %} -Copy this config on a second server, edit it to replace the riak_hostname and riak_nodename. On the first server, start it like show previously, then on the second, with +Copy this config on a second server, edit it to replace the riak\_hostname and riak\_nodename. On the first server, start it like show previously, then on the second, with {% highlight bash %} -./start-join.sh config/riak-demo.erlenv 192.168.0.11 +% ./start-join.sh config/riak-demo.erlenv 192.168.0.11 {% endhighlight %} where the IP address it the address of the first node in your cluster. @@ -70,11 +70,11 @@ where the IP address it the address of the first node in your cluster. Let's check if everything works: {% highlight bash %} -curl -X PUT -H "Content-type: application/json" \ +% curl -X PUT -H "Content-type: application/json" \ http://192.168.0.11:8098/jiak/blog/lumberjaph/ \ -d "{\"bucket\":\"blog\",\"key\":\"lumberjaph\",\"object\":{\"title\":\"I'm a lumberjaph, and I'm ok\"},\"links\":[]}" -curl -i http://192.168.0.11:8098/jiak/blog/lumberjaph/ +% curl -i http://192.168.0.11:8098/jiak/blog/lumberjaph/ {% endhighlight %} will output (with the HTTP blabla) @@ -83,7 +83,7 @@ will output (with the HTTP blabla) {"object":{"title":"I'm a lumberjaph, and I'm ok"},"vclock":"a85hYGBgzGDKBVIsbGubKzKYEhnzWBlCTs08wpcFAA==","lastmod":"Sun, 13 Dec 2009 20:28:04 GMT","vtag":"5YSzQ7sEdI3lABkEUFcgXy","bucket":"blog","key":"lumberjaph","links":[]} {% endhighlight %} -h3. Using Riak with Perl and KiokuDB +## Using Riak with Perl and KiokuDB I need to store various things in Riak: html pages, json data, and objects using KiokuDB. I've started to write a client for Riak with AnyEvent, so I can do simple operations at the moment, (listing information about a bucket, defining a new bucket with a specific schema, storing, retriving and deleting documents). To create a client, you need to @@ -108,8 +108,8 @@ my $client = AnyEvent::Riak->new( where: - * the W and DW values define that the request returns as soon as at least W nodes have received the request, and at least DW nodes have stored it in their storage backend. - * with the R value, the request returns as soon as R nodes have responded with a value or an error. You can also set this values when calling fetch, store and delete. By default, the value is set to 2. +* the W and DW values define that the request returns as soon as at least W nodes have received the request, and at least DW nodes have stored it in their storage backend. +* with the R value, the request returns as soon as R nodes have responded with a value or an error. You can also set this values when calling fetch, store and delete. By default, the value is set to 2. So, if you wan to store a value, retrieve it, then delete it, you can do: @@ -121,8 +121,7 @@ my $fetch = $client->fetch('foo', 'bar')->recv; my $delete = $client->delete('foo', 'bar')->recv; {% endhighlight %} -If there is an error, the croak method from AnyEvent is used, so you may -prefer to do this: +If there is an error, the croak method from AnyEvent is used, so you may prefer to do this: {% highlight perl %} use Try::Tiny; |
