MySQLのインストール

 

MySQLCentOSにインストールしてみました。


環境

OS:CentOS6.4

 

インストール

 yum -y install mysql-server

設定の変更

文字コードをUTF8にします。

$ sudo vim /etc/my.cnf

character-set-server = utf8

MysSQLサーバの起動

$ sudo /etc/rc.d/init.d/mysqld start

初期設定

$ mysql_secure_installation

ログイン

$ mysql -u root -p

DB作成

testDBを作ります。

mysql> create database test;

ユーザ作成

ユーザ作成testDBの権限があるtestユーザを作りました。

mysql> grant all privileges on test.* to test@localhost identified by 'パスワード';

作成したtestユーザでログイン

$ mysql -u test -p

リモート接続

リモート接続用のユーザ作成

ローカルIPからのみ接続できるtestユーザを作成しました。

mysql> grant all on test.* to test@"192.168.%" identified by 'パスワード'

ユーザが作成されたか確認するコマンド

mysql> select user, host from mysql.user;
ポートを開ける。デフォルトの3306をあけました。 
$ sudo vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
$ sudo /etc/init.d/iptables restart
DBのアクセス元設定
sudo vim /etc/my.cnf
bind-address = 0.0.0.0 ←この設定を削除する
sudo /etc/rc.d/init.d/mysqld restart
bind-addressは複数IP指定できないようなので設定を削除しました。
アクセス制御する場合はhosts.allowとかでやるとよさそうです。
 
a5で接続
こんな感じで設定する
f:id:katashiyo515:20140316194052p:plain
 
接続できました。

資料

 

CentOSにOracleを入れる

無料でOracleが使いたい。

ということで、Oracle Database Express Edition 11g Release 2CentOSに入れてみました。

環境

OS:CentOS6.4

要件
glibcは2.3.4-2.41以上
makeは3.80以上
binutilsは2.16.91.0.5以上
gccは4.1.2以上
libaioは0.3.104以上
下準備
インストール
$ yum install glibc
$ yum install make
$ yum install gcc
$ yum install binutils
$ yum install libaio
$ yum install libaio-devel
$ yum install bc

Hostsの設定

デフォルトの設定ではtnsname.oraがhost名になっているので、ホスト名とipが紐づいていない場合エラーになります。

ホスト名を127.0.0.1に設定します。

ホスト名の確認

$ hostname

centOS64mini

ホスト名の設定

$ sudo vim /etc/hosts

127.0.0.1   localhost  centOS64mini5 

デフォルトポートの解放

# 8080と1521を開ける
$ sudo /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT                       
-A INPUT -m state --state NEW -m tcp -p tcp --dport 1521 -j ACCEPT
# リスタート 
$ /etc/init.d/iptablesrestart
解凍 

unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip

インストール
スワップ領域を一時的に2GBに設定。2GB以上ある場合はこの作業は不要です。

SWAPサイズを一時的に増やす : Edo::World::Blogこちらを参考にすると変更できます。

# 現在の領域を削除
$ sudo swapoff -a
 
# 2GBの領域を作成する
$ sudo dd if=/dev/zero of=/tmp/swapfile bs=1M count=2048
$ sudo mkswap /tmp/swapfile
$ sudo swapon /tmp/swapfile
 
# 確認
$ cat /proc/swaps
インストール
sudo rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm
sudo /etc/init.d/oracle-xe configure
swap領域を元に戻す
# 現在の領域を削除
sudo swapoff -a
# swap領域を元に戻す
sudo swapon /dev/mapper/VolGroup-lv_swap
# 確認
sudo cat /proc/swaps
# 作ったスワップファイルを削除
sudo rm /tmp/swapfile
インストール完了。
 
※エラーが出た場合はここにログが出るので確認する

/u01/app/oracle/product/11.2.0/xe/config/log/ 

ユーザ作成

ORACLE_HOMEの設定

$ cat ~/.bashrc
# .bashrc
# Source global definitions                                                
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
 
# User specific aliases and functions 
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=${ORACLE_BASE}/product/11.2.0/xe
export ORACLE_SID=XE
export ORACLE_BASE=/u01/app/oracle
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib/:/lib:/usr/lib
export NLS_LANG=Japanese_Japan.AL32UTF8
 
$ source .bashrc

oracleユーザのパスワード変更

$ sudo passwd oracle 

oracleユーザでsqlplusにログイン

$ su oracle
$ sqlplus / as sysdba

# testユーザをパスワードpasswordで作成
SQL > create user test
identified by password
default tablespace USERS
temporary tablespace TEMP;
# 権限の付与
SQL > grant CONNECT to TEST;
SQL > grant create table to TEST;
# ログアウト
SQL > exit;

testユーザで テーブル作成

# ログイン

$ sqlplus test/password@XE

# テーブル作成

SQL >  create table test

(
  id NUMBER(3) ,
  name VARCHAR2(5),
  primary key( id )
);
windowsからログインしてみる 

A5:SQL Mk-2を使います。

データベース→データベースの追加と削除→追加→Oracle(OCI経由 or 直接接続)
こんな感じに設定をすればOKです。
 

f:id:katashiyo515:20131223191942j:plain

ポート番号やサービス名を変更したい場合はtnsnames.oraを修正するといいです。

/u01/app/oracle/product/11.2.0/xe/network/admin/tnsnames.ora

 

Cassandraを動かす

 nosqlの代表格Cassandraを使ってみます

cassandraのページ

http://cassandra.apache.org

環境

OS:CentOS6.4

ダウンロード

$ wget http://www.apache.org/dyn/closer.cgi?path=/cassandra/2.0.3/apache-cassandra-2.0.3-bin.tar.gz

解凍

$ tar zxvf apache-cassandra-2.0.3-bin.tar.gz

設定

デフォルトの設定で動かすことにします。

# フォルダの作成
$ sudo mkdir -p /var/lib/cassandra/data/system/local
$ sudo mkdir -/var/cassandora/{data,commitlog,saved_caches}

# hostsの設定

$ hostname
centOS64mini

$ vim /etc/hosts

127.0.0.1   localhost centOS64mini

 サーバの起動

cassandraサーバを動かす

sudo ./bin/cassandra

 DBの作成

cassandraに接続する

$ ./bin/cassandra-cli -h localhost

作成

# keyspaceの作成
[default@unknown] create keyspace ks1;
# 作成したkeyspaceを使う
[default@unknown] use ks1;
column familyの作成
[default@ks1] create column family cf1 with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type;
データの保存と取得

保存

$ ./bin/cassandra-cli -h localhost
[default@ks1] set cf1['key1']['col1']='value1';

 取得

$ ./bin/cassandra-cli -h localhost

[default@ks1] get cf1['key1'];
=> (name=col1, value=value1, timestamp=1387578152513000)
Returned 1 results.
Elapsed time: 125 msec(s).

無事に取得できました。

もちろん、phppythonなど様々な言語に対応しているのでそこからの保存と取得も可能です

ClientOptions_JP - Cassandra Wiki

 

 参考資料

 

LevelDBをつかってみた

RocksDBやRiakで使われているLevelDBを使ってみました。

leveldb - A fast and lightweight key/value database library by Google. - Google Project Hosting

環境

CentOS6.4

ダウンロード

gitかwgetでダウンロードできます。

Downloads - leveldb - A fast and lightweight key/value database library by Google. - Google Project Hosting

インストール
$ sudo yum install gcc-c++
$ sudo yum install snappy
※snappyはいらないかもしれません。
 
ダウンロードしたleveldbのフォルダに移動してmakeする 

$ cd leveldb

$ make

$ make check

libとincludeをコピー

$ sudo cp libleveldb.a /usr/local/lib

$ sudo cp -r include/leveldb /usr/local/include

Cのコードをかく

保存用のコード

$ cat save.cc
#include "leveldb/db.h"
#include <iostream>
#include <assert.h>
 
int main(int argc, char *argv) {
    if (argc != 3) {
        printf("usage : ./save key value\n");
        return 1;
    }
    // 引数を変数に設定
    std::string key(argv[1]);
    std::string value(argv[2]);
 
    // dbの読み込み
    leveldb::DB* db;
    leveldb::Options options;
    options.create_if_missing = true;
    leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);
    // DBの読み込みチェック
    assert(status.ok());
 
    // 保存処理
    status = db->Put(leveldb::WriteOptions(), key, value);
    assert(status.ok());
    std::cout << "set (key, value) = (" << key << ", " << value << ")" << std::endl;
 
}

取得用のコード

$ cat load.cc
#include "leveldb/db.h"
#include <iostream>
#include <assert.h>
 
int main(int argc, char *argv) {
    if (argc != 2) {
        printf("usage : ./load key\n");
        return 1;
    }
    // 引数を変数に設定
    std::string key(argv[1]);
    std::string value;
 
    // dbの読み込み
    leveldb::DB* db;
    leveldb::Options options;
    options.create_if_missing = true;
    leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);
    // DBの読み込みチェック
    assert(status.ok());
 
    // 読み込み処理
    status = db->Get(leveldb::ReadOptions(), key, &value);
    if (status.ok()) {
        std::cout << "load (key, value) = (" << key << ", " << value << ")" << std::endl;
    } else {
        std::cout << "Not found" << std::endl;
    }
 
}

削除用のコード

$ cat delete.cc
#include "leveldb/db.h"
#include <iostream>
#include <assert.h>
 
int main(int argc, char *argv[]) {
    if (argc != 2) {
        printf("usage : ./delete key\n");
        return 1;
    }
    // 引数を変数に設定
    std::string key(argv[1]);
 
    // dbの読み込み
    leveldb::DB* db;
    leveldb::Options options;
    options.create_if_missing = true;
    leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);
    // DBの読み込みチェック
    assert(status.ok());
 
    // 読み込み処理
    status = db->Delete(leveldb::WriteOptions(), key);
    assert(status.ok());
    std::cout << "Deleted key(" << key << ")" << std::endl;
 
}
 コンパイルして実行

コンパイル

 

$ g++ -o save save.cc /usr/local/lib/libleveldb.a -lpthread -I /usr/local/include/leveldb/
$ g++ -o load load.cc /usr/local/lib/libleveldb.a -lpthread -I /usr/local/include/leveldb/
$ g++ -o delete delete.cc /usr/local/lib/libleveldb.a -lpthread -I /usr/local/include/leveldb/

実行

$ ./save key1 value1
set (key, value) = (key1, value1)
 
$ ./load key1
load (key, value) = (key1, value1)
 
$ ./delete key1
Deleted key(key1)
 
$ ./load key1
Not found

動作OK!

資料

leveldb - A fast and lightweight key/value database library by Google. - Google Project Hosting

A quick guide to LevelDB

MongoDBインストール

MongoDBを使ってみました。

今回は時間がないのでインストールのみです。

環境

OS:CentOS6.4

インストール

環境に合わせたインストール手順はこちらです。
 
CentOSなのでyumでインストールしました。
 
mongodb.repoというレポジトリvimで追加します
$ cat /etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
gpgcheck=0
enabled=0
※enabled=0にしてデフォルトでは使えない状態にしています
 
作成したリポジトリを有効にしてインストール
sudo yum install --enablerepo=mongodb mongo-10gen mongo-10gen-server
 
これでインストールは完了です。

mongoサーバの起動

コマンド1つで起動できます

sudo service mongod start

サーバの容量が 3.4GB以上ない場合は、エラーが出てしまいます。

$ sudo service mongod start
Starting mongod: about to fork child process, waiting until server is ready for connections.
forked process: 1698
all output going to: /var/log/mongo/mongod.log
ERROR: child process failed, exited with error number 100
                                                           [失敗]
エラーログを見ると、journal filesが3379MB必要らしいです。
sudo less /var/log/mongo/mongod.log
 
Tue Dec 17 00:10:12.189 [initandlisten] journal dir=/var/lib/mongo/journal
Tue Dec 17 00:10:12.194 [initandlisten] recover : no journal files present, no recovery needed
Tue Dec 17 00:10:12.196 [initandlisten]
Tue Dec 17 00:10:12.196 [initandlisten] ERROR: Insufficient free space for journal files
Tue Dec 17 00:10:12.199 [initandlisten] Please make at least 3379MB available in /var/lib/mongo/journal or use --smallfiles
Tue Dec 17 00:10:12.199 [initandlisten]

容量もないのでnojournal=trueに設定を変更します。

 

 sudo vim /etc/mongod.conf

 18 # Disables write-ahead journaling
 19 # nojournal = true
 
 
 18 # Disables write-ahead journaling
 19 nojournal = true

設定変更後は無事起動できました。

$ sudo service mongod start

Starting mongod: about to fork child process, waiting until server is ready for connections.

forked process: 5086

all output going to: /var/log/mongo/mongod.log

child process started successfully, parent exiting

 

                                                           [  OK  ]

クライアントから実行

利用できるクライアントはphpruby、scalaなどたくさんあります

Install MongoDB — MongoDB Manual 2.4.8

今回もphpを使ってmongoDBを利用します。
手順はThe MongoDB Blogと同じです。
 
phpizeを使えるようにする

sudo yum install php-devel

phpのmongoライブラリをインストール

sudo pecl install mongo

 php.iniに設定を追加

$ cat /etc/php.d/myext.ini
extension=mongo.so
保存

phpからmongoDBに保存。

$ cat save.php
<?php
 
// DATA
$user = array(
    'first_name' => 'MongoDB',
    'last_name' => 'Fan',
    'tags' => array('developer','user')
);
 
// Configuration
$dbhost = 'localhost';
$dbname = 'test';
 
// Connect to test database
$m = new Mongo("mongodb://$dbhost");
$db = $m->$dbname;
 
// Get the users collection
$c_users = $db->users;
 
// Insert this new document into the users collection
$c_users->save($user);
実行
php save.php
データの確認
mongoのtestDBにログインして確認。oracleのsqlplusのようなものです。
$ mongo test
MongoDB shell version: 2.4.8
connecting to: test
> show collections;
system.indexes
users
> db.users.findOne()
{
        "_id" : ObjectId("52af1de83b5823ab138b4567"),
        "first_name" : "MongoDB",
        "last_name" : "Fan",
        "tags" : [
                "developer",
                "user"
        ]
}
読み込み

読み込みコード

$ cat load.php
<?php
// Configuration
$dbhost = 'localhost';
$dbname = 'test';
 
// Connect to test database
$m = new Mongo("mongodb://$dbhost");
$db = $m->$dbname;
 
// Get the users collection
$c_users = $db->users;
 
// Find the user with first_name 'MongoDB' and last_name 'Fan'
$user = array(
                                'first_name' => 'MongoDB',
                                'last_name' => 'Fan'
                         );
 
$user = $c_users->findOne($user);
var_dump($user);
実行
$ php load.php
array(4) {
  ["_id"]=>
  object(MongoId)#6 (1) {
    ["$id"]=>
    string(24) "52af1de83b5823ab138b4567"
  }
  ["first_name"]=>
  string(7) "MongoDB"
  ["last_name"]=>
  string(3) "Fan"
  ["tags"]=>
  array(2) {
    [0]=>
    string(9) "developer"
    [1]=>
    string(4) "user"
  }
}
 無事に保存と取得ができました!

Riakのめも

Riak Meetup Tokyo #3 - connpassでRiakについて勉強してきました。

Riakとは

Bashoが作ったkvs。MapReduceに対応していて、Riak2.0では全文検索ができるようになるらしい。

講演で気になった単語はこんな感じです。

  • key-valueのDB
  • Secondary Index(2i)
  • Map Reduce
  • Counter
  • Full Text Search(Riak2.0)
  • バケットタイプ(Riak2.0)
  • 強い整合性(Riak2.0)
  • セキュリティ(Riak2.0)
  • Stanchon
  • LevelDB
  • APIから操作できる
  • RiakCS(Cloud Storage)

知らないことばかりなので、とりあえず動かしてみることに。

Riakのインストール

UbuntuRHELFreeBSDなど環境に合わせて導入方法がまとまっています。

http://docs.basho.com/riak/latest/quickstart/

CentOSはyumでインストールできるのでその通りコマンドをうつ

sudo yum install http://yum.basho.com/gpg/basho-release-6-1.noarch.rpm

sudo yum install riak

 インストール完了。簡単!

Riackの起動

riak start

sudo riak start

!!!!

!!!! WARNING: ulimit -n is 1024; 4096 is the recommended minimum.

!!!!

WARNINGでた。。パッと見大丈夫そうなのでとりあえずriak pingで起動確認

riak ping

pong

 pongと出ているので動いている。ちなみに止まってる場合はこうでる。

riak ping

Node 'riak@127.0.0.1' not responding to pings.

 

 クライアントからset、getする

講演中、Erlangだから運用が大変だよってな話があったので、クライアントはErlangだけかと勘違いしてました。
調べてみたらjava,php,python,c,rubyなんでもあります。勘違い恥ずかしい。。

http://docs.basho.com/riak/latest/dev/using/libraries/

使い慣れているphpでクライアントを動かしてみます。

 

gitにphpのクライアントコードがあるので取得

git clone git://github.com/basho/riak-php-client.git

 

サンプルをもとに保存と取得のコードを作成
保存用のphp(riaksave.php

<?php

require_once('riak-php-client/src/Basho/Riak/Riak.php');

require_once('riak-php-client/src/Basho/Riak/Bucket.php');

require_once('riak-php-client/src/Basho/Riak/Exception.php');

require_once('riak-php-client/src/Basho/Riak/Link.php');

require_once('riak-php-client/src/Basho/Riak/MapReduce.php');

require_once('riak-php-client/src/Basho/Riak/Object.php');

require_once('riak-php-client/src/Basho/Riak/StringIO.php');

require_once('riak-php-client/src/Basho/Riak/Utils.php');

require_once('riak-php-client/src/Basho/Riak/Link/Phase.php');

require_once('riak-php-client/src/Basho/Riak/MapReduce/Phase.php');

 

$client = new Basho\Riak\Riak('127.0.0.1', 8098);

 

$bucket = $client->bucket('test');

 

$key   = "key_test";

$value = array('test1' => "value1", 'test2' => 10);

 

$person = $bucket->newObject($key, $value);

//$person = $bucket->newObject($key);

//$person->setData($value);

 

$person->store();

取得用のphp(riakload.php

 <?php

require_once('riak-php-client/src/Basho/Riak/Riak.php');

require_once('riak-php-client/src/Basho/Riak/Bucket.php');

require_once('riak-php-client/src/Basho/Riak/Exception.php');

require_once('riak-php-client/src/Basho/Riak/Link.php');

require_once('riak-php-client/src/Basho/Riak/MapReduce.php');

require_once('riak-php-client/src/Basho/Riak/Object.php');

require_once('riak-php-client/src/Basho/Riak/StringIO.php');

require_once('riak-php-client/src/Basho/Riak/Utils.php');

require_once('riak-php-client/src/Basho/Riak/Link/Phase.php');

require_once('riak-php-client/src/Basho/Riak/MapReduce/Phase.php');

$client = new Basho\Riak\Riak('127.0.0.1', 8098);

$bucket = $client->bucket('test');

$key = "key_test";

// get value from "key_test" key

$riak_data = $bucket->get('key_test');

echo 'riak_data->data is = ' . var_export($riak_data->data, true) . "\n";

実行してみます。 

php riaksave.php

php riaklead.php

riak_data->data is = array (

  'test1' => 'value1',

  'test2' => 10,

)

 保存と取得ができてます。簡単!!

API経由での利用

Riakの利点の1つAPI経由でkeyの取得を試してみます。

testバケットのkey_testキーの値を取得

curl http://localhost:8098/buckets/test/keys/key_test

{"test1":"value1","test2":10}

 

とれた!!

 

 

サンプルコードを見る限り取得だけでなくAPI経由で保存もできそうな感じです。

 

セカンダリインデックス(2i)

Riakの特徴 2つ目、セカンダリインデックス。

通常のインデックスはテーブルに持たせるものですが、keyにインデックスを持たせる(タグを付けられる)ことができます。(間違っていたらすみません。)

インデックス作成コード(riaksave_index.php

<?php

require_once('riak-php-client/src/Basho/Riak/Riak.php');

require_once('riak-php-client/src/Basho/Riak/Bucket.php');

require_once('riak-php-client/src/Basho/Riak/Exception.php');

require_once('riak-php-client/src/Basho/Riak/Link.php');

require_once('riak-php-client/src/Basho/Riak/MapReduce.php');

require_once('riak-php-client/src/Basho/Riak/Object.php');

require_once('riak-php-client/src/Basho/Riak/StringIO.php');

require_once('riak-php-client/src/Basho/Riak/Utils.php');

require_once('riak-php-client/src/Basho/Riak/Link/Phase.php');

require_once('riak-php-client/src/Basho/Riak/MapReduce/Phase.php');

 

$client = new Basho\Riak\Riak('127.0.0.1', 8098);

 

$bucket = $client->bucket('game');

 

$ps3 = $bucket->newObject("playstation3", array("release" => "20061111"));

// add index

$ps3->addIndex("myindex", "int", 1);

$ps3->addIndex("maker", "bin", "sony");

$ps3->store();

 

$ps4 = $bucket->newObject("playstation4", array("release" => "20140220"));

$ps4->addIndex("myindex", "int", 2);

$ps4->addIndex("maker", "bin", "sony");

$ps4->store();

 

$wii = $bucket->newObject("wiiu", array("release" => "20121208"));

$wii->addIndex("myindex", "int", 3);

$wii->addIndex("maker", "bin", "nintendo");

$wii->store();

 

$xbox = $bucket->newObject("xboxone", array("release" => "2014"));

$xbox->addIndex("myindex", "int", 4);

$xbox->addIndex("maker", "bin", "microsoft");

$xbox->store();

インデックスから取得

curl http://localhost:8098/buckets/game/index/maker_bin/sony

<html><head><title>500 Internal Server Error</title></head><body><h1>Internal Server Error</h1>The server encountered an error while processing this request:<br><pre>{error,{error,insufficient_vnodes_available}}</pre><P><HR><ADDRESS>mochiweb+webmachine web server

エラーが出た。。。 

どうもLevelDBを使う必要があるらしい。

http://docs.basho.com/riak/latest/dev/using/2i/

http://docs.basho.com/riak/latest/ops/advanced/backends/leveldb/

設定を変更

sudo vim /etc/riak/app.config

 83             %% {storage_backend, riak_kv_bitcask_backend},

 84             {storage_backend, riak_kv_eleveldb_backend}, 

設定を反映

sudo riak restart

ok

 あらためてインデックスから取得

curl http://localhost:8098/buckets/game/index/maker_bin/sony

{"keys":["playstation3","playstation4"]}

 今度は取れました。sonyで検索してplaystation3,playstation4がとれています。

今度はphpから

インデックスから取得(riakload_index.php

<?php

require_once('riak-php-client/src/Basho/Riak/Riak.php');

require_once('riak-php-client/src/Basho/Riak/Bucket.php');

require_once('riak-php-client/src/Basho/Riak/Exception.php');

require_once('riak-php-client/src/Basho/Riak/Link.php');

require_once('riak-php-client/src/Basho/Riak/MapReduce.php');

require_once('riak-php-client/src/Basho/Riak/Object.php');

require_once('riak-php-client/src/Basho/Riak/StringIO.php');

require_once('riak-php-client/src/Basho/Riak/Utils.php');

require_once('riak-php-client/src/Basho/Riak/Link/Phase.php');

require_once('riak-php-client/src/Basho/Riak/MapReduce/Phase.php');

 

$client = new Basho\Riak\Riak('127.0.0.1', 8098);

 

$bucket = $client->bucket('game');

 

# Exact Match

echo "===== start exact match =====\n";

$results = $bucket->indexSearch("maker", "bin", "sony");

foreach ($results as $link) {

    $key      = $link->getKey();

    $riakdata = $link->get();

    echo "Key: {$key} , Value: " . var_export($riakdata->data,true) . "\n";

}

 

# Range Search

echo "===== start range search(int) =====\n";

$results = $bucket->indexSearch("myindex", "int", 1, 4);

foreach ($results as $link) {

    $key      = $link->getKey();

    $riakdata = $link->get();

    echo "Key: {$key} , Value: " . var_export($riakdata->data,true) . "\n";

}

 

# Range Search

echo "===== start range search(bin) =====\n";

$results = $bucket->indexSearch("maker", "bin", "sony", "nintendo");

foreach ($results as $link) {

    $key      = $link->getKey();

    $riakdata = $link->get();

    echo "Key: {$key} , Value: " . var_export($riakdata->data,true) . "\n";

}

 

実行(php riakload_index.php

===== start exact match =====

Key: playstation3 , Value: array (

  'release' => '20061111',

)

Key: playstation4 , Value: array (

  'release' => '20140220',

)

===== start range search(int) =====

Key: playstation3 , Value: array (

  'release' => '20061111',

)

Key: playstation4 , Value: array (

  'release' => '20140220',

)

Key: wiiu , Value: array (

  'release' => '20121208',

)

Key: xboxone , Value: array (

  'release' => '2014',

)

===== start range search(bin) =====

Key: wiiu , Value: array (

  'release' => '20121208',

)

Key: playstation3 , Value: array (

  'release' => '20061111',

)

Key: playstation4 , Value: array (

  'release' => '20140220',

)

ちゃんと取得できてます。int型なら範囲指定で取得できるようです。

 

ps4ほしいなぁ。。 

 

資料

 

Riak

Basho Japan | Basho makes Riak, an open source database.

Bashoジャパン主催「Riak Meetup Tokyo」参加レポート - Yahoo! JAPAN Tech Blog(6月くらいのやつ)

Yokozuna: Riak2.0の新しい全文検索機能 // Speaker Deck

 

Riak 2.0 pre5 @ Riak Meetup #3

Riak Meetup Tokyo #3 - connpass

Twitter / Search - #riakjp

Riakのソースコードリーディングがあるみたいです。
Riak Source Code Reading #14 - connpass