macbook airにcassandraを入れる
そういや、home brew入れてたんだっけ
$ brew info cassandra
cassandra 1.0.2
http://cassandra.apache.org
Not installed
If this is your first install, automatically load on login with:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/cassandra/1.0.2/org.apache.cassandra.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/org.apache.cassandra.plist
ふむ。現在の最新は1.0.3らしいけど、とりあえずいいや。
$ brew install cassandra
==> Downloading http://www.apache.org/dyn/closer.cgi?path=/cassandra/1.0.2/apach
==> Best Mirror http://www.meisei-u.ac.jp/mirror/apache/dist//cassandra/1.0.2/ap
curl: (22) The requested URL returned error: 404
Error: Download failed: http://www.apache.org/dyn/closer.cgi?path=/cassandra/1.0.2/apache-cassandra-1.0.2-bin.tar.gz
ありゃ、失敗した。
brew edit cassandra
でurl を適当なmirrorに置き換えてやる。ついでだし1.0.3にすっか。
$brew install cassandra
で当然ながらMD5 mismatchになるので、実際に取得したMD5の値に置き換える。
(これはよくないなw)
そしてもう一度
$brew install cassandra
でインストール完了 => /usr/local/Cellar/cassandra/1.0.3/
あとはその中のREADME.txtを読んでいじってみる。
起動(foreground mode)
$bin/cassandra -f
クライアント起動
$bin/cassandra-cli --host localhost
キースペース作成
[default@unknown] create keyspace Keyspace1;
キースペース選択
[default@unknown] use Keyspace1;
Usersカラムファミリー作成
create column family Users with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type;
Userカラムファミリーのjsmithキーのfirstカラムにvalueとして'John'をセット
[default@Keyspace1] set Users[jsmith][first] = 'John';
Value inserted.
Elapsed time: 61 msec(s).
初回は結構時間かかるようだ。
同様に
[default@Keyspace1] set Users[jsmith][last] = 'Smith';
Value inserted.
Elapsed time: 2 msec(s).
longで入れてみたり
[default@Keyspace1] set Users[jsmith][age] = long(42);
Value inserted.
Elapsed time: 5 msec(s).
今度はカラムごとgetしてみる
[default@Keyspace1] get Users[jsmith];
=> (column=age, value=42, timestamp=1321692710792000)
=> (column=first, value=John, timestamp=1321692566291000)
=> (column=last, value=Smith, timestamp=1321692589969000)
Returned 3 results.
Elapsed time: 37 msec(s).
もう一度同じことをやってみる。
[default@Keyspace1] get Users[jsmith];
=> (column=age, value=42, timestamp=1321692710792000)
=> (column=first, value=John, timestamp=1321692566291000)
=> (column=last, value=Smith, timestamp=1321692589969000)
Returned 3 results.
Elapsed time: 6 msec(s).
この場合はrow単位でキャッシュされてるのかな。
今度はageを連続で取得してみる
[default@Keyspace1] get Users[jsmith][age];
=> (column=age, value=42, timestamp=1321692710792000)
Elapsed time: 16 msec(s).
[default@Keyspace1] get Users[jsmith][age];
=> (column=age, value=42, timestamp=1321692710792000)
Elapsed time: 4 msec(s).
カラム単位でもキャッシュされてるようだ。
lastの方はどうだろう。
[default@Keyspace1] get Users[jsmith][last];
=> (column=last, value=Smith, timestamp=1321692589969000)
Elapsed time: 3 msec(s).
[default@Keyspace1] get Users[jsmith][last];
=> (column=last, value=Smith, timestamp=1321692589969000)
Elapsed time: 4 msec(s).
なんか知らんが最初から早い。
でも書き込みからしてlongより早かったしな。
年齢をインクリメントしてみる。
[default@Keyspace1] set Users[jsmith][age] = long(43);
Value inserted.
Elapsed time: 2 msec(s).
[default@Keyspace1] get Users[jsmith][age];
=> (column=age, value=43, timestamp=1321694120414000)
Elapsed time: 4 msec(s).
んー。書き込み早い。初回のはカラム作る分遅かったのかな。
とりあえず一旦終了
[default@Keyspace1]exit;