master
bel 2019-06-26 18:42:25 -06:00
parent 95aa3f85fe
commit f807cc71b2
1 changed files with 0 additions and 73 deletions

73
riak.go
View File

@ -1,73 +0,0 @@
package storage
import (
"errors"
riak "github.com/basho/riak-go-client"
)
type Riak struct {
db *riak.Client
}
func NewRiak(addr string, addrs ...string) (*Riak, error) {
return nil, ErrNotImpl
clientOpts := &riak.NewClientOptions{
RemoteAddresses: append(addrs, addr),
}
db, err := riak.NewClient(clientOpts)
if err != nil {
return nil, err
}
ok, err := db.Ping()
if !ok {
return nil, ErrCantConnect
}
return &Riak{
db: db,
}, err
}
func (r *Riak) List(ns []string, limits ...string) ([]string, error) {
return nil, errors.New("not impl")
}
func (r *Riak) Get(key string, ns ...string) ([]byte, error) {
namespace := resolveNamespace(ns)
obj := &riak.Object{}
cmd, err := riak.NewFetchValueCommandBuilder().
WithBucket(namespace).
WithKey(key).
Build()
if err != nil {
return nil, err
}
err = r.db.Execute(cmd)
return obj.Value, err
}
func (r *Riak) Set(key string, value []byte, ns ...string) error {
namespace := resolveNamespace(ns)
obj := &riak.Object{
Value: value,
}
cmd, err := riak.NewStoreValueCommandBuilder().
WithBucket(namespace).
WithContent(obj).
Build()
if err != nil {
return err
}
return r.db.Execute(cmd)
}
func (r *Riak) Close() error {
return r.db.Stop()
}