Documentation ¶
Index ¶
- type Client
- type Config
- type MultiClient
- func (m *MultiClient) CAS(ctx context.Context, key string, ...) error
- func (m *MultiClient) Get(ctx context.Context, key string) (interface{}, error)
- func (m *MultiClient) Stop()
- func (m *MultiClient) WatchKey(ctx context.Context, key string, f func(interface{}) bool)
- func (m *MultiClient) WatchPrefix(ctx context.Context, prefix string, f func(string, interface{}) bool)
- type MultiConfig
- type MultiRuntimeConfig
- type StoreConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // Get a spefic key. Will use a codec to deserialise key to appropriate type. Get(ctx context.Context, key string) (interface{}, error) // CAS stands for Compare-And-Swap. Will call provided callback f with the // current value of the key and allow callback to return a different value. // Will then attempt to atomically swap the current value for the new value. // If that doesn't succeed will try again - callback will be called again // with new value etc. Guarantees that only a single concurrent CAS // succeeds. Callback can return nil to indicate it is happy with existing // value. CAS(ctx context.Context, key string, f func(in interface{}) (out interface{}, retry bool, err error)) error // WatchKey calls f whenever the value stored under key changes. WatchKey(ctx context.Context, key string, f func(interface{}) bool) // WatchPrefix calls f whenever any value stored under prefix changes. WatchPrefix(ctx context.Context, prefix string, f func(string, interface{}) bool) // If client needs to do some cleanup, it can do it here. Stop() }
Client is a high-level client for key-value stores (such as Etcd and Consul) that exposes operations such as CAS and Watch which take callbacks. It also deals with serialisation by using a Codec and having a instance of the the desired type passed in to methods ala json.Unmarshal.
func NewClient ¶
NewClient creates a new Client (consul, etcd or inmemory) based on the config, encodes and decodes data for storage using the codec.
func PrefixClient ¶
PrefixClient takes a KVClient and forces a prefix on all its operations.
type Config ¶
type Config struct { Store string `yaml:"store,omitempty"` Prefix string `yaml:"prefix,omitempty"` StoreConfig `yaml:",inline"` Mock Client `yaml:"-"` }
Config is config for a KVStore currently used by ring and HA tracker, where store can be consul or inmemory.
func (*Config) RegisterFlagsWithPrefix ¶
RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet. If prefix is an empty string we will register consul flags with no prefix and the store flag with the prefix ring, so ring.store. For everything else we pass the prefix to the Consul flags. If prefix is not an empty string it should end with a period.
type MultiClient ¶ added in v0.6.0
type MultiClient struct {
// contains filtered or unexported fields
}
MultiClient implements kv.Client by forwarding all API calls to primary client. Writes performed via CAS method are also (optionally) forwarded to secondary clients.
func NewMultiClient ¶ added in v0.6.0
func NewMultiClient(cfg MultiConfig, clients []kvclient) *MultiClient
NewMultiClient creates new MultiClient with given KV Clients. First client in the slice is the primary client.
func (*MultiClient) CAS ¶ added in v0.6.0
func (m *MultiClient) CAS(ctx context.Context, key string, f func(in interface{}) (out interface{}, retry bool, err error)) error
CAS is a part of kv.Client interface.
func (*MultiClient) Get ¶ added in v0.6.0
func (m *MultiClient) Get(ctx context.Context, key string) (interface{}, error)
Get is a part of kv.Client interface.
func (*MultiClient) Stop ¶ added in v0.6.0
func (m *MultiClient) Stop()
Stop the multiClient and all configured clients.
func (*MultiClient) WatchKey ¶ added in v0.6.0
func (m *MultiClient) WatchKey(ctx context.Context, key string, f func(interface{}) bool)
WatchKey is a part of kv.Client interface.
func (*MultiClient) WatchPrefix ¶ added in v0.6.0
func (m *MultiClient) WatchPrefix(ctx context.Context, prefix string, f func(string, interface{}) bool)
WatchPrefix is a part of kv.Client interface.
type MultiConfig ¶ added in v0.6.0
type MultiConfig struct { Primary string `yaml:"primary"` Secondary string `yaml:"secondary"` MirrorEnabled bool `yaml:"mirror_enabled"` MirrorTimeout time.Duration `yaml:"mirror_timeout"` // ConfigProvider returns channel with MultiRuntimeConfig updates. ConfigProvider func() <-chan MultiRuntimeConfig `yaml:"-"` }
MultiConfig is a configuration for MultiClient.
func (*MultiConfig) RegisterFlagsWithPrefix ¶ added in v0.6.0
func (cfg *MultiConfig) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix string)
RegisterFlagsWithPrefix registers flags with prefix.
type MultiRuntimeConfig ¶ added in v0.6.0
type MultiRuntimeConfig struct { // Primary store used by MultiClient. Can be updated in runtime to switch to a different store (eg. consul -> etcd, // or to gossip). Doing this allows nice migration between stores. Empty values are ignored. PrimaryStore string `yaml:"primary"` // Mirroring enabled or not. Nil = no change. Mirroring *bool `yaml:"mirror_enabled"` }
MultiRuntimeConfig has values that can change in runtime (via overrides)
type StoreConfig ¶ added in v0.6.0
type StoreConfig struct { Consul consul.Config `yaml:"consul,omitempty"` Etcd etcd.Config `yaml:"etcd,omitempty"` Memberlist memberlist.Config `yaml:"memberlist,omitempty"` Multi MultiConfig `yaml:"multi,omitempty"` }
StoreConfig is a configuration used for building single store client, either Consul, Etcd, Memberlist or MultiClient. It was extracted from Config to keep single-client config separate from final client-config (with all the wrappers)