redis の公式サイトは Ruby/Redis で構築されている。
アプリ(以下 redis-io)そのものが github で公開されているので、実際にインストールしてみた。
ドキュメントを一部書き換えて、本家とは別にローカルで を運用することなどを想定。

antirez/redis-io/ という環境構築ドキュメントがあり、予想に反して、書いてある通りに操作すれば動いたのだけど、せっかくなので記録として残してみる。

Ruby のインストール

できるだけまっさら環境からの構築ということで、rvm で Ruby 1.9.3 をインストール。

$ rvm use 1.9.3
ruby ruby-1.9.3-p0 is not installed.
To install do: 'rvm install ruby-1.9.3-p0'

$ rvm install ruby-1.9.3-p0
Installing Ruby from source to: /home/user/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)...

ruby-1.9.3-p0 - #fetching
ruby-1.9.3-p0 - #downloading ruby-1.9.3-p0, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 9330k  100 9330k    0     0  3230k      0  0:00:02  0:00:02 --:--:-- 3466k
ruby-1.9.3-p0 - #extracting ruby-1.9.3-p0 to /home/user/.rvm/src/ruby-1.9.3-p0
ruby-1.9.3-p0 - #extracted to /home/user/.rvm/src/ruby-1.9.3-p0
ruby-1.9.3-p0 - #configuring
ruby-1.9.3-p0 - #compiling
ruby-1.9.3-p0 - #installing
Removing old Rubygems files...
Installing rubygems-1.8.15 for ruby-1.9.3-p0 ...
Installation of rubygems completed successfully.
ruby-1.9.3-p0 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.3-p0 - #importing default gemsets (/home/user/.rvm/gemsets/)
Install of ruby-1.9.3-p0 - #complete

$ rvm use 1.9.3
Using /home/user/.rvm/gems/ruby-1.9.3-p0


$ git clone
Cloning into 'redis-doc'...
remote: Counting objects: 2987, done.
remote: Compressing objects: 100% (1017/1017), done.
remote: Total 2987 (delta 2084), reused 2856 (delta 1961)
Receiving objects: 100% (2987/2987), 589.67 KiB | 222 KiB/s, done.
Resolving deltas: 100% (2084/2084), done.


$ export REDIS_DOC=`pwd`/redis-doc

redis-io をチェックアウト

メインアプリの redis-io をチェックアウト

$ git clone
Cloning into 'redis-io'...
remote: Counting objects: 1887, done.
remote: Compressing objects: 100% (636/636), done.
remote: Total 1887 (delta 1211), reused 1869 (delta 1193)
Receiving objects: 100% (1887/1887), 977.22 KiB | 197 KiB/s, done.
Resolving deltas: 100% (1211/1211), done.


dep 経由で必要なパッケージをインストールする

Specify your project’s dependencies in one file.

$ cd redis-io
$ cat .gems
cuba -v 2.2.1
haml -v 3.1.4
ohm -v 0.1.5
rdiscount -v 1.6.8
nokogiri -v 1.5.2
compass -v 0.12.1

$ gem install dep
Fetching: clap-0.0.2.gem (100%)
Fetching: dep-1.0.1.gem (100%)
Successfully installed clap-0.0.2
Successfully installed dep-1.0.1
2 gems installed
Installing ri documentation for clap-0.0.2...
Installing ri documentation for dep-1.0.1...
Installing RDoc documentation for clap-0.0.2...
Installing RDoc documentation for dep-1.0.1...

Successfully installed dep-1.0.1
1 gem installed
Installing ri documentation for dep-1.0.1...
Installing RDoc documentation for dep-1.0.1...

$ dep install
  gem install cuba -v 2.2.1
  gem install haml -v 3.1.4
  gem install ohm -v 0.1.5
  gem install rdiscount -v 1.6.8
  gem install nokogiri -v 1.5.2
  gem install compass -v 0.12.1


Cuba is a microframework for web applications.

Haml (HTML Abstraction Markup Language) is a layer on top of XHTML or XML that’s designed to express the structure of XHTML or XML documents in a non-repetitive, elegant, easy way, using indentation rather than closing tags and allowing Ruby to be embedded with ease. It was originally envisioned as a plugin for Ruby on Rails, but it can function as a stand-alone templating engine.

Ohm is a library that allows to store an object in Redis, a persistent key-value database. It includes an extensible list of validations and has very good performance.

Fast Implementation of Gruber’s Markdown in C

Nokogiri is an HTML, XML, SAX, and Reader parser. Among Nokogiri’s many features is the ability to search documents via XPath or CSS3 selectors. XML is like violence – if it doesn’t solve your problems, you are not using enough of it.

Compass is a Sass-based Stylesheet Framework that streamlines the creation and maintainance of CSS.


$ ruby -e 'require "cuba"'
$ ruby -e 'require "haml"'
$ ruby -e 'require "ohm"'
$ ruby -e 'require "rdiscount"'
$ ruby -e 'require "nokogiri"'
$ ruby -e 'require "compass"'

Nokogiri のインストールでエラー発生
nokogiri のインストール中にエラーが発生した。

$ gem install nokogiri
Fetching: nokogiri-1.5.3.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
        ERROR: Failed to build gem native extension.

        /home/user/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for libxml/parser.h... no
libxml2 is missing.  please visit for help with installing dependencies.
*** extconf.rb failed ***

エラーメッセージにある URL の指示に従って、必要なパッケージをインストールすればよい。
ubuntu の場合は以下のパッケージが必要。

# ruby developer packages
sudo apt-get install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8
sudo apt-get install libreadline-ruby1.8 libruby1.8 libopenssl-ruby

# nokogiri requirements
sudo apt-get install libxslt-dev libxml2-dev
sudo gem install nokogiri

redis の起動
redis-io サイトではコマンドのページで redis コマンドを実行出来る作りになっており(実装は lib/interactive/session.rb. 調べていて初めてしった)、セッション別コマンドの管理に redis が利用されている。


対応する redis 操作

1339469062.203274 [0] "zscore" "sessions" "81a099887cd400d83a0f8fd16abfe92b"
1339469062.203734 [0] "zadd" "sessions" "1339469062" "81a099887cd400d83a0f8fd16abfe92b"
1339469062.204226 [0] "zrangebyscore" "sessions" "-inf" "1339465462" "LIMIT" "0" "1" "WITHSCORES"
1339469062.205080 [0] "sadd" "session:81a099887cd400d83a0f8fd16abfe92b:keys" "foo"
1339469062.205447 [0] "incr" "session:81a099887cd400d83a0f8fd16abfe92b:commands"
1339469062.205807 [0] "set" "81a099887cd400d83a0f8fd16abfe92b:foo" "hoge"


$ ./redis-server
[17590] 12 Jun 21:04:05.382 # Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf'
[17590] 12 Jun 21:04:05.384 # Unable to set the max number of files limit to 10032 (Operation not permitted), setting the max clients configuration to 3984.
[17590] 12 Jun 21:04:05.385 # Warning: 32 bit instance detected but no memory limit set. Setting 3.5 GB maxmemory limit with 'noeviction' policy now. の起動
最後にようやくメインアプリ の起動

$ REDIS_DOC=/home/user/dev/redis-doc
$ rackup
[2012-06-12 21:04:11] INFO  WEBrick 1.3.1
[2012-06-12 21:04:11] INFO  ruby 1.9.3 (2011-10-30) [i686-linux]
[2012-06-12 21:04:11] INFO  WEBrick::HTTPServer#start: pid=17593 port=9292

あとはブラウザで http://HOST:9292/ にアクセスすればOK



$ gem install cutest capybara
Fetching: cutest-1.1.3.gem (100%)
Successfully installed cutest-1.1.3
Fetching: mime-types-1.18.gem (100%)
Fetching: multi_json-1.3.6.gem (100%)
Fetching: rubyzip-0.9.8.gem (100%)
Fetching: ffi-1.0.11.gem (100%)
Building native extensions.  This could take a while...
Fetching: childprocess-0.3.2.gem (100%)
Fetching: addressable-2.2.8.gem (100%)
Fetching: libwebsocket-0.1.3.gem (100%)
Fetching: selenium-webdriver-2.22.2.gem (100%)
Fetching: rack-test-0.6.1.gem (100%)
Fetching: xpath-0.1.4.gem (100%)
Fetching: capybara-1.1.2.gem (100%)
Successfully installed mime-types-1.18
Successfully installed multi_json-1.3.6
Successfully installed rubyzip-0.9.8
Successfully installed ffi-1.0.11
Successfully installed childprocess-0.3.2
Successfully installed addressable-2.2.8
Successfully installed libwebsocket-0.1.3
Successfully installed selenium-webdriver-2.22.2
Successfully installed rack-test-0.6.1
Successfully installed xpath-0.1.4
Successfully installed capybara-1.1.2
12 gems installed
Installing ri documentation for cutest-1.1.3...
Installing ri documentation for mime-types-1.18...
Installing ri documentation for multi_json-1.3.6...
Installing ri documentation for rubyzip-0.9.8...
Installing ri documentation for ffi-1.0.11...
Installing ri documentation for childprocess-0.3.2...
Installing ri documentation for addressable-2.2.8..

Run tests in separate processes to avoid shared state.

Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website



$ REDIS_DOC=/home/user/dev/redis-doc rake


$ REDIS_DOC=/home/user/dev/redis-doc cutest test/command_reference.rb

NOTE : テストの実行には Redis が必要

Tagged with: ,
Posted in database

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: