rubygems の riak-client-1.4.3 が ruby-1.8.7 で Syntax Error
7つのデータベース 7つの世界という書籍でデータベースについて勉強中です。特にNoSQLやKey Value Storeと言われるデータベースを実際にインストールして動かしながら学ぶには非常に良い本だと思います。ちなみに理論だけで良ければNOSQLの基礎知識という書籍がオススメです。
さて、この7つのデータベース 7つの世界で紹介されている7つのデータベースの1つが Riak という Key Value型 のデータベースです。この書籍では、Ruby の Riakドライバを使って1万件のデータを Riakサーバー に格納する作業があり、Rubygems の riak-client を使っています。
ですが、ここで書籍に書かれているとおりに
$ gem install riak-client
でRiakドライバーをダウンロードして、以下のRubyコードを実行すると、
# generate loads and loads of rooms with random styles and capacities require 'rubygems' require 'riak' STYLES = %w{single double queen king suite} client = Riak::Client.new(:http_port => 8091) bucket = client.bucket('rooms') # Create 100 floors to the building for floor in 1..100 current_rooms_block = floor * 100 puts "Making rooms #{current_rooms_block} - #{current_rooms_block + 100}" # Put 100 rooms on each floor (huge hotel!) for room in 1...100 # Create a unique room number as the key ro = Riak::RObject.new(bucket, (current_rooms_block + room)) # Randomly grab a room style, and make up a capacity style = STYLES[rand(STYLES.length)] capacity = rand(8) + 1 # Store the room information as a JSON value ro.content_type = "application/json" ro.data = {'style' => style, 'capacity' => capacity} ro.store end end
3行目の「require 'riak'」で以下のようなRubyの構文エラー(Syntex Error)が発生してしまいます。
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client/http_backend.rb:195: syntax error, unexpected ':', expecting kEND (SyntaxError) stream_opts = options.merge keys: 'stream' ^ /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client/http_backend.rb:198: syntax error, unexpected ':', expecting kEND list_opts = options.merge keys: true ^ /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client/http_backend.rb:209: syntax error, unexpected ':', expecting ')' ...ist_path(options.merge(stream: true)), &BucketStreamer.new(b... ^ /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client/http_backend.rb:209: syntax error, unexpected ')', expecting kEND /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client/http_backend.rb:302: syntax error, unexpected ':', expecting ')' ...index.wrong_backend', backend: match[1]) ^ /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client/http_backend.rb:302: syntax error, unexpected ')', expecting kEND /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client/http_backend.rb:347: syntax error, unexpected kDO_BLOCK, expecting kEND response = get(200, luwak_path(filename)) do |chunk| ^ /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client/http_backend.rb:348: syntax error, unexpected tIDENTIFIER, expecting kEND /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client/http_backend.rb:352: syntax error, unexpected kENSURE, expecting kEND /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client/http_backend.rb:397: syntax error, unexpected kDO_BLOCK, expecting kEND {}.tap do |result| ^ /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client/http_backend.rb:401: syntax error, unexpected kDO_BLOCK, expecting kEND result['docs'] = json['response']['docs'].map do |d| ^ /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client/http_backend.rb:413: syntax error, unexpected $end, expecting kEND from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require' from /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak/client.rb:11 from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require' from /var/lib/gems/1.8/gems/riak-client-1.4.2/lib/riak.rb:3 from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:59:in `gem_original_require' from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:59:in `require' from hotel.rb:3
とりあえずコマンドで古い v1.2.0 の riak-client をインストールし、Syntax Error を回避しました。
$ gem install riak-client -v 1.2.0