kvproto

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2018 License: Apache-2.0 Imports: 3 Imported by: 79

Documentation

Overview

Package kvproto provides a wrapper that simplifies the storing and retrieving of proto-modelled data into/from a key-value data store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWatchResp

func NewWatchResp(serializer keyval.Serializer, resp keyval.BytesWatchResp) keyval.ProtoWatchResp

NewWatchResp initializes proto watch response from raw WatchResponse <resp>.

Types

type ProtoWrapper

type ProtoWrapper struct {
	// contains filtered or unexported fields
}

ProtoWrapper is a decorator which allows to read/write proto file modelled data. It marshals/unmarshals go structures to slice of bytes and vice versa behind the scenes.

func NewProtoWrapper

func NewProtoWrapper(db keyval.CoreBrokerWatcher) *ProtoWrapper

NewProtoWrapper initializes proto decorator. The default serializer is used - SerializerProto.

func NewProtoWrapperWithSerializer

func NewProtoWrapperWithSerializer(db keyval.CoreBrokerWatcher, serializer keyval.Serializer) *ProtoWrapper

NewProtoWrapperWithSerializer initializes proto decorator with the specified serializer.

func (*ProtoWrapper) Close

func (db *ProtoWrapper) Close() error

Close closes underlying connection to ETCD. Beware: if the connection is shared among multiple instances, this might unintentionally cancel the connection for them.

func (*ProtoWrapper) Delete

func (db *ProtoWrapper) Delete(key string, opts ...datasync.DelOption) (existed bool, err error)

Delete removes key-value items stored under <key> from datastore.

func (*ProtoWrapper) GetValue

func (db *ProtoWrapper) GetValue(key string, reqObj proto.Message) (found bool, revision int64, err error)

GetValue retrieves one key-value item from the datastore. The item is identified by the provided <key>.

If the item was found, its value is unmarshaled and placed in the <reqObj> message buffer and the function returns <found> as *true*. If the object was not found, the function returns <found> as *false*. Function also returns the revision of the latest modification. Any encountered error is returned in <err>.

func (*ProtoWrapper) ListKeys

func (db *ProtoWrapper) ListKeys(prefix string) (keyval.ProtoKeyIterator, error)

ListKeys returns an iterator that allows to traverse all keys that share the given <prefix> from data store.

func (*ProtoWrapper) ListValues

func (db *ProtoWrapper) ListValues(key string) (keyval.ProtoKeyValIterator, error)

ListValues retrieves an iterator for elements stored under the provided <key>.

func (*ProtoWrapper) NewBroker

func (db *ProtoWrapper) NewBroker(prefix string) keyval.ProtoBroker

NewBroker creates a new instance of the proxy that shares the underlying connection and allows to read/edit key-value pairs.

func (*ProtoWrapper) NewTxn

func (db *ProtoWrapper) NewTxn() keyval.ProtoTxn

NewTxn creates a new Data Broker transaction. A transaction can hold multiple operations that are all committed to the data store together. After a transaction has been created, one or more operations (put or delete) can be added to the transaction before it is committed.

func (*ProtoWrapper) NewWatcher

func (db *ProtoWrapper) NewWatcher(prefix string) keyval.ProtoWatcher

NewWatcher creates a new instance of the proxy that shares the underlying connection and allows subscribing for watching of the changes.

func (*ProtoWrapper) Put

func (db *ProtoWrapper) Put(key string, value proto.Message, opts ...datasync.PutOption) error

Put writes the provided key-value item into the data store. It returns an error if the item could not be written, nil otherwise.

func (*ProtoWrapper) Watch

func (db *ProtoWrapper) Watch(resp func(keyval.ProtoWatchResp), closeChan chan string, keys ...string) error

Watch subscribes for changes in datastore associated with any of the <keys>. Callback <resp> is used for delivery of watch events. Channel <closeChan> is used to close key-related goroutines Any encountered error is returned as well

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL