前人未踏の領域へ Androidアプリ開発編

Androidアプリ開発に関する調査メモ置き場。古い記事にはアプリ以外も含まれます。

『7つのデータベース7つの世界』Riak編をやってみる。

Riakのインストールについてはこちらから

1日目 CRUD、リンク、MIMEタイプ

テスト環境作成
$cd $RIAK_HOME
$make devrel
//テストサーバー起動
$dev/dev1/bin/riak start
$dev/dev2/bin/riak start
$dev/dev3/bin/riak start

それぞれ動作確認
http://127.0.0.1:10018/stats
http://127.0.0.1:10028/stats
http://127.0.0.1:10038/stats

クラスタ
$dev/dev2/bin/riak-admin join dev1@127.0.0.1

すると

The 'join' command has been deprecated in favor of the new 
clustering commands provided by 'riak-admin cluster'. To continue 
using the deprecated 'join' command, use 'join -f'

拒否される。1.3ではjoinは非推奨らしい。代わりにclusterコマンドを使う。

$ dev/dev2/bin/riak-admin cluster join dev1@127.0.0.1
Success: staged join request for 'dev2@127.0.0.1' to 'dev1@127.0.0.1'

同様にdev3もつなぐ。

$ dev/dev3/bin/riak-admin cluster join dev2@127.0.0.1
Success: staged join request for 'dev3@127.0.0.1' to 'dev2@127.0.0.1'

http://127.0.0.1:10018/statsにアクセスし、"connected_nodes"を確認するとそれぞれを認識している事が確認できる。

"connected_nodes": [
"dev2@127.0.0.1",
"dev3@127.0.0.1"
]

停止すると

$dev/dev2/bin/riak stop

消える。

"connected_nodes": [
"dev3@127.0.0.1"
]
RESST

ping

$ curl http://localhost:10018/ping
OK

間違ったキー入力

$ curl -I http://localhost:10018/riak/no_bucket/no_key
HTTP/1.1 404 Object Not Found
Server: MochiWeb/1.1 WebMachine/1.9.2 (someone had painted it blue)
Date: Sun, 10 Mar 2013 09:15:33 GMT
Content-Type: text/plain
Content-Length: 10

HTMLをPUTしてみる。

$ curl -v -X PUT http://localhost:10018/riak/favs/db \
> -H "Content-Type: text/html" \
> -d "<html><body><h1>My new favorite DB is RIAK</h1></body></html>"
* About to connect() to localhost port 10018 (#0)
*   Trying ::1...
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 10018 (#0)
> PUT /riak/favs/db HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:10018
> Accept: */*
> Content-Type: text/html
> Content-Length: 61
> 
* upload completely sent off: 61 out of 61 bytes
< HTTP/1.1 204 No Content
< Vary: Accept-Encoding
< Server: MochiWeb/1.1 WebMachine/1.9.2 (someone had painted it blue)
< Date: Sun, 10 Mar 2013 09:22:40 GMT
< Content-Type: text/html
< Content-Length: 0
< 
* Connection #0 to host localhost left intact

成功すればHTMLが表示される
http://localhost:10018/riak/favs/db

値をバケットにPUTする
//$ curl -v -X PUT http://localhost:10018/riak/BUCKET/KEY 
$ curl -v -X PUT http://localhost:10018/riak/animals/ace \
> -H "Content-Type: application/json" \
> -d '{"nickname" : "The Wonder Dog", "bread" : "German Shepherd"}'
* About to connect() to localhost port 10018 (#0)
*   Trying ::1...
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 10018 (#0)
> PUT /riak/animals/ace HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:10018
> Accept: */*
> Content-Type: application/json
> Content-Length: 60
> 
* upload completely sent off: 60 out of 60 bytes
< HTTP/1.1 204 No Content
< Vary: Accept-Encoding
< Server: MochiWeb/1.1 WebMachine/1.9.2 (someone had painted it blue)
< Date: Sun, 10 Mar 2013 16:06:31 GMT
< Content-Type: application/json
< Content-Length: 0
< 
* Connection #0 to host localhost left intact

作成されたバケットの一覧を表示

$ curl -X GET http://localhost:10018/riak?buckets=true
{"buckets":["favs","animals"]}