3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Go言語:Riakに書き込む

Posted at

この記事の目的

  • Go言語でRiakに書き込むプログラムを作成する

Riakとは?

  • 分散型キーバリューデータベース
  • RESTFul APIを通して読み書きする
  • 単一障害点がなく耐障害性がある
  • スケールが容易

Riakのクライアントライブラリを入手する

go get github.com/tpjg/goriakpbc

実装する

main.go
package main

import (
	"github.com/tpjg/goriakpbc"
	"log"
)

func main() {
	err := riak.ConnectClient("127.0.0.1:8087")
	
	if err != nil {
		log.Fatal(err)
	}

	bucket, err := riak.NewBucket("hoge")

	if err != nil {
		log.Fatal(err)
	}

	obj := bucket.NewObject("fuga")
	obj.ContentType = "application/json"
	obj.Data = []byte(`{"foo":"bar"}`)
	err = obj.Store()

	if err != nil {
		log.Fatal(err)
	}

	riak.Close()
}

実行する

go run main.go

書き込めた!

rekon_v1_0_0-4.png

ちなみにこの画面はRiakのGUI管理ツールRekon。Riakの開発元が作っている。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?