riak简介(一)

本人机子为ubuntu。所以安装比较简单

sudo apt-get install openssl
sudo apt-get install erlang
下载deb包安装
wget -c http://s3.amazonaws.com/downloads.basho.com/riak/2.0/2.0.2/ubuntu/trusty/riak_2.0.2-1_amd64.deb
dpkg -i riak_2.0.2-1_amd64.deb

就此安装完成。喜欢用源码安装的同学也请考虑上面的依赖。不难,只不过可能有点麻烦。

启动riak服务

sudo riak start

具体的配置文件请看
/etc/riak/riak.conf


http默认的监听端口为 
127.0.0.1:8098

因为是第一篇,所以暂时使用单节点,讲解简单的操作。

  • 添加
     curl -i -H "Content-Type: plain/text" -d "Some text" http://localhost:8098/riak/foo返回
    HTTP/1.1 201 Created
    Vary: Accept-Encoding
    Server: MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
    Location: /riak/foo/86qDc77dbesWX651mgSYKLqSDSW
    Date: Mon, 12 Jan 2015 15:10:58 GMT
    Content-Type: plain/text
    Content-Length: 0
    上面使用的是hash key。当然,我们可以使用指定的key:
    curl -i -d '{"name":"Bruce"}' -H "Content-Type: application/json" http://localhost:8098/riak/artists/Bruce
    
    返回:
    HTTP/1.1 204 No Content
    Vary: Accept-Encoding
    Server: MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
    Date: Mon, 12 Jan 2015 15:22:23 GMT
    Content-Type: application/json
    Content-Length: 0
    
    观察可以看到如果我们存储文本成功的时候返回的代码为201.存储对象成功的时候返回的是204 No Content。另外值得注意的地方还有Content-Type.通过修改Conten-Type,我们可以存储图像等其他mime类型消息。
  • 查询
    curl -i http://localhost:8098/riak/artists/Bruce
    
    返回:
    HTTP/1.1 200 OK
    X-Riak-Vclock: a85hYGBgzGDKBVIcypz/fj7T3PktgymRMY+VYX2Sxjm+LAA=
    Vary: Accept-Encoding
    Server: MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
    Link: ; rel="up"
    Last-Modified: Mon, 12 Jan 2015 15:22:23 GMT
    ETag: "41UXK3bSSH2tRZ4Ft6OlKH"
    Date: Mon, 12 Jan 2015 15:35:38 GMT
    Content-Type: application/json
    Content-Length: 16
    
    {"name":"Bruce"}
  • 更新
    curl -i -X PUT -d '{"name":"Bruce", "nickname":"The Boss"}' -H "Content-Type: application/json" http://localhost:8098/riak/artists/Bruce
    返回:
    HTTP/1.1 204 No Content
    Vary: Accept-Encoding
    Server: MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
    Date: Mon, 12 Jan 2015 15:40:35 GMT
    Content-Type: application/json
    Content-Length: 0
  • 删除
    curl -i -X DELETE http://localhost:8098/riak/artists/Bruce
    返回:
    BruceHTTP/1.1 204 No Content
    Vary: Accept-Encoding
    Server: MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
    Date: Mon, 12 Jan 2015 15:43:02 GMT
    Content-Type: application/json
    Content-Length: 0
    
    删除了之后再去Get得到的是404

riak的基础操作介绍的差不多了。作为一个web开发者,感叹其实现的RESTful如此优雅。

你可能感兴趣的:(编程实践,存储)