Documentation
¶
Overview ¶
Package olric provides a distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service.
With Olric, you can instantly create a fast, scalable, shared pool of RAM across a cluster of computers.
Olric is designed to be a distributed cache. But it also provides Publish/Subscribe, data replication, failure detection and simple anti-entropy services. So it can be used as an ordinary key/value data store to scale your cloud application.
Index ¶
- Constants
- Variables
- type Client
- type ClusterClient
- func (cl *ClusterClient) Close(ctx context.Context) error
- func (cl *ClusterClient) Members(ctx context.Context) ([]Member, error)
- func (cl *ClusterClient) NewDMap(name string, options ...DMapOption) (DMap, error)
- func (cl *ClusterClient) NewPubSub(options ...PubSubOption) (*PubSub, error)
- func (cl *ClusterClient) Ping(ctx context.Context, addr, message string) (string, error)
- func (cl *ClusterClient) RefreshMetadata(ctx context.Context) error
- func (cl *ClusterClient) RoutingTable(ctx context.Context) (RoutingTable, error)
- func (cl *ClusterClient) Stats(ctx context.Context, address string, options ...StatsOption) (stats.Stats, error)
- type ClusterClientOption
- type ClusterDMap
- func (dm *ClusterDMap) Decr(ctx context.Context, key string, delta int) (int, error)
- func (dm *ClusterDMap) Delete(ctx context.Context, keys ...string) (int, error)
- func (dm *ClusterDMap) Destroy(ctx context.Context) error
- func (dm *ClusterDMap) Expire(ctx context.Context, key string, timeout time.Duration) error
- func (dm *ClusterDMap) Get(ctx context.Context, key string) (*GetResponse, error)
- func (dm *ClusterDMap) GetPut(ctx context.Context, key string, value interface{}) (*GetResponse, error)
- func (dm *ClusterDMap) Incr(ctx context.Context, key string, delta int) (int, error)
- func (dm *ClusterDMap) IncrByFloat(ctx context.Context, key string, delta float64) (float64, error)
- func (dm *ClusterDMap) Lock(ctx context.Context, key string, deadline time.Duration) (LockContext, error)
- func (dm *ClusterDMap) LockWithTimeout(ctx context.Context, key string, timeout, deadline time.Duration) (LockContext, error)
- func (dm *ClusterDMap) Name() string
- func (dm *ClusterDMap) Pipeline(opts ...PipelineOption) (*DMapPipeline, error)
- func (dm *ClusterDMap) Put(ctx context.Context, key string, value interface{}, options ...PutOption) error
- func (dm *ClusterDMap) Scan(ctx context.Context, options ...ScanOption) (Iterator, error)
- type ClusterIterator
- type ClusterLockContext
- type DMap
- type DMapOption
- type DMapPipeline
- func (dp *DMapPipeline) Close()
- func (dp *DMapPipeline) Decr(ctx context.Context, key string, delta int) (*FutureDecr, error)
- func (dp *DMapPipeline) Delete(ctx context.Context, key string) *FutureDelete
- func (dp *DMapPipeline) Discard() error
- func (dp *DMapPipeline) Exec(ctx context.Context) error
- func (dp *DMapPipeline) Expire(ctx context.Context, key string, timeout time.Duration) (*FutureExpire, error)
- func (dp *DMapPipeline) Get(ctx context.Context, key string) *FutureGet
- func (dp *DMapPipeline) GetPut(ctx context.Context, key string, value interface{}) (*FutureGetPut, error)
- func (dp *DMapPipeline) Incr(ctx context.Context, key string, delta int) (*FutureIncr, error)
- func (dp *DMapPipeline) IncrByFloat(ctx context.Context, key string, delta float64) (*FutureIncrByFloat, error)
- func (dp *DMapPipeline) Put(ctx context.Context, key string, value interface{}, options ...PutOption) (*FuturePut, error)
- type EmbeddedClient
- func (e *EmbeddedClient) Close(_ context.Context) error
- func (e *EmbeddedClient) Members(_ context.Context) ([]Member, error)
- func (e *EmbeddedClient) NewDMap(name string, options ...DMapOption) (DMap, error)
- func (e *EmbeddedClient) NewPubSub(options ...PubSubOption) (*PubSub, error)
- func (e *EmbeddedClient) Ping(ctx context.Context, addr, message string) (string, error)
- func (e *EmbeddedClient) RefreshMetadata(_ context.Context) error
- func (e *EmbeddedClient) RoutingTable(ctx context.Context) (RoutingTable, error)
- func (e *EmbeddedClient) Stats(ctx context.Context, address string, options ...StatsOption) (stats.Stats, error)
- type EmbeddedDMap
- func (dm *EmbeddedDMap) Decr(ctx context.Context, key string, delta int) (int, error)
- func (dm *EmbeddedDMap) Delete(ctx context.Context, keys ...string) (int, error)
- func (dm *EmbeddedDMap) Destroy(ctx context.Context) error
- func (dm *EmbeddedDMap) Expire(ctx context.Context, key string, timeout time.Duration) error
- func (dm *EmbeddedDMap) Get(ctx context.Context, key string) (*GetResponse, error)
- func (dm *EmbeddedDMap) GetPut(ctx context.Context, key string, value interface{}) (*GetResponse, error)
- func (dm *EmbeddedDMap) Incr(ctx context.Context, key string, delta int) (int, error)
- func (dm *EmbeddedDMap) IncrByFloat(ctx context.Context, key string, delta float64) (float64, error)
- func (dm *EmbeddedDMap) Lock(ctx context.Context, key string, deadline time.Duration) (LockContext, error)
- func (dm *EmbeddedDMap) LockWithTimeout(ctx context.Context, key string, timeout, deadline time.Duration) (LockContext, error)
- func (dm *EmbeddedDMap) Name() string
- func (dm *EmbeddedDMap) Pipeline(opts ...PipelineOption) (*DMapPipeline, error)
- func (dm *EmbeddedDMap) Put(ctx context.Context, key string, value interface{}, options ...PutOption) error
- func (dm *EmbeddedDMap) Scan(ctx context.Context, options ...ScanOption) (Iterator, error)
- type EmbeddedIterator
- type EmbeddedLockContext
- type FutureDecr
- type FutureDelete
- type FutureExpire
- type FutureGet
- type FutureGetPut
- type FutureIncr
- type FutureIncrByFloat
- type FuturePut
- type GetResponse
- func (g *GetResponse) Bool() (bool, error)
- func (g *GetResponse) Byte() ([]byte, error)
- func (g *GetResponse) Duration() (time.Duration, error)
- func (g *GetResponse) Float32() (float32, error)
- func (g *GetResponse) Float64() (float64, error)
- func (g *GetResponse) Int() (int, error)
- func (g *GetResponse) Int16() (int16, error)
- func (g *GetResponse) Int32() (int32, error)
- func (g *GetResponse) Int64() (int64, error)
- func (g *GetResponse) Int8() (int8, error)
- func (g *GetResponse) Scan(v interface{}) error
- func (g *GetResponse) String() (string, error)
- func (g *GetResponse) TTL() int64
- func (g *GetResponse) Time() (time.Time, error)
- func (g *GetResponse) Timestamp() int64
- func (g *GetResponse) Uint() (uint, error)
- func (g *GetResponse) Uint16() (uint16, error)
- func (g *GetResponse) Uint32() (uint32, error)
- func (g *GetResponse) Uint64() (uint64, error)
- func (g *GetResponse) Uint8() (uint8, error)
- type Iterator
- type LockContext
- type Member
- type Olric
- type PipelineOption
- type PubSub
- func (ps *PubSub) PSubscribe(ctx context.Context, channels ...string) *redis.PubSub
- func (ps *PubSub) PubSubChannels(ctx context.Context, pattern string) ([]string, error)
- func (ps *PubSub) PubSubNumPat(ctx context.Context) (int64, error)
- func (ps *PubSub) PubSubNumSub(ctx context.Context, channels ...string) (map[string]int64, error)
- func (ps *PubSub) Publish(ctx context.Context, channel string, message interface{}) (int64, error)
- func (ps *PubSub) Subscribe(ctx context.Context, channels ...string) *redis.PubSub
- type PubSubOption
- type PutOption
- type Route
- type RoutingTable
- type ScanOption
- type StatsOption
Constants ¶
const DefaultPingResponse = "PONG"
const DefaultRoutingTableFetchInterval = time.Minute
DefaultRoutingTableFetchInterval is the default value of RoutingTableFetchInterval. ClusterClient implementation fetches the routing table from the cluster to route requests to the right partition.
const DefaultScanCount = 10
const ReleaseVersion string = "0.2.0-alpha"
ReleaseVersion is the current stable version of Olric
Variables ¶
var ( // ErrOperationTimeout is returned when an operation times out. ErrOperationTimeout = errors.New("operation timeout") // ErrServerGone means that a cluster member is closed unexpectedly. ErrServerGone = errors.New("server is gone") // ErrKeyNotFound means that returned when a key could not be found. ErrKeyNotFound = errors.New("key not found") // ErrKeyFound means that the requested key found in the cluster. ErrKeyFound = errors.New("key found") // ErrWriteQuorum means that write quorum cannot be reached to operate. ErrWriteQuorum = errors.New("write quorum cannot be reached") // ErrReadQuorum means that read quorum cannot be reached to operate. ErrReadQuorum = errors.New("read quorum cannot be reached") // ErrLockNotAcquired is returned when the requested lock could not be acquired ErrLockNotAcquired = errors.New("lock not acquired") // ErrNoSuchLock is returned when the requested lock does not exist ErrNoSuchLock = errors.New("no such lock") // ErrClusterQuorum means that the cluster could not reach a healthy numbers of members to operate. ErrClusterQuorum = errors.New("failed to find enough peers to create quorum") // ErrKeyTooLarge means that the given key is too large to process. // Maximum length of a key is 256 bytes. ErrKeyTooLarge = errors.New("key too large") // ErrEntryTooLarge returned if the required space for an entry is bigger than table size. ErrEntryTooLarge = errors.New("entry too large for the configured table size") // ErrConnRefused returned if the target node refused a connection request. // It is good to call RefreshMetadata to update the underlying data structures. ErrConnRefused = errors.New("connection refused") )
var ( // ErrNotReady denotes that the Future instance you hold is not ready to read the response yet. ErrNotReady = errors.New("not ready yet") // ErrPipelineClosed denotes that the underlying pipeline is closed, and it's impossible to operate. ErrPipelineClosed = errors.New("pipeline is closed") // ErrPipelineExecuted denotes that Exec was already called on the underlying pipeline. ErrPipelineExecuted = errors.New("pipeline already executed") )
var ErrNilResponse = errors.New("storage entry is nil")
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // NewDMap returns a new DMap client with the given options. NewDMap(name string, options ...DMapOption) (DMap, error) // NewPubSub returns a new PubSub client with the given options. NewPubSub(options ...PubSubOption) (*PubSub, error) // Stats returns stats.Stats with the given options. Stats(ctx context.Context, address string, options ...StatsOption) (stats.Stats, error) // Ping sends a ping message to an Olric node. Returns PONG if message is empty, // otherwise return a copy of the message as a bulk. This command is often used to test // if a connection is still alive, or to measure latency. Ping(ctx context.Context, address, message string) (string, error) // RoutingTable returns the latest version of the routing table. RoutingTable(ctx context.Context) (RoutingTable, error) // Members returns a thread-safe list of cluster members. Members(ctx context.Context) ([]Member, error) // RefreshMetadata fetches a list of available members and the latest routing // table version. It also closes stale clients, if there are any. RefreshMetadata(ctx context.Context) error // Close stops background routines and frees allocated resources. Close(ctx context.Context) error }
Client is an interface that denotes an Olric client.
type ClusterClient ¶
type ClusterClient struct {
// contains filtered or unexported fields
}
func NewClusterClient ¶
func NewClusterClient(addresses []string, options ...ClusterClientOption) (*ClusterClient, error)
NewClusterClient creates a new Client instance. It needs one node address at least to discover the whole cluster.
func (*ClusterClient) Close ¶
func (cl *ClusterClient) Close(ctx context.Context) error
Close stops background routines and frees allocated resources.
func (*ClusterClient) Members ¶
func (cl *ClusterClient) Members(ctx context.Context) ([]Member, error)
Members returns a thread-safe list of cluster members.
func (*ClusterClient) NewDMap ¶
func (cl *ClusterClient) NewDMap(name string, options ...DMapOption) (DMap, error)
NewDMap returns a new DMap client with the given options.
func (*ClusterClient) NewPubSub ¶
func (cl *ClusterClient) NewPubSub(options ...PubSubOption) (*PubSub, error)
NewPubSub returns a new PubSub client with the given options.
func (*ClusterClient) Ping ¶
Ping sends a ping message to an Olric node. Returns PONG if message is empty, otherwise return a copy of the message as a bulk. This command is often used to test if a connection is still alive, or to measure latency.
func (*ClusterClient) RefreshMetadata ¶
func (cl *ClusterClient) RefreshMetadata(ctx context.Context) error
RefreshMetadata fetches a list of available members and the latest routing table version. It also closes stale clients, if there are any.
func (*ClusterClient) RoutingTable ¶
func (cl *ClusterClient) RoutingTable(ctx context.Context) (RoutingTable, error)
RoutingTable returns the latest version of the routing table.
func (*ClusterClient) Stats ¶
func (cl *ClusterClient) Stats(ctx context.Context, address string, options ...StatsOption) (stats.Stats, error)
Stats returns stats.Stats with the given options.
type ClusterClientOption ¶
type ClusterClientOption func(c *clusterClientConfig)
func WithConfig ¶
func WithConfig(c *config.Client) ClusterClientOption
func WithHasher ¶
func WithHasher(h hasher.Hasher) ClusterClientOption
func WithLogger ¶
func WithLogger(l *log.Logger) ClusterClientOption
func WithRoutingTableFetchInterval ¶
func WithRoutingTableFetchInterval(interval time.Duration) ClusterClientOption
WithRoutingTableFetchInterval is used to set a custom value to routingTableFetchInterval. ClusterClient implementation retrieves the routing table from the cluster to route requests to the partition owners.
type ClusterDMap ¶
type ClusterDMap struct {
// contains filtered or unexported fields
}
ClusterDMap implements a client for DMaps.
func (*ClusterDMap) Decr ¶
Decr atomically decrements the key by delta. The return value is the new value after being decremented or an error.
func (*ClusterDMap) Delete ¶
Delete deletes values for the given keys. Delete will not return error if key doesn't exist. It's thread-safe. It is safe to modify the contents of the argument after Delete returns.
func (*ClusterDMap) Destroy ¶
func (dm *ClusterDMap) Destroy(ctx context.Context) error
Destroy flushes the given DMap on the cluster. You should know that there is no global lock on DMaps. So if you call Put/PutEx and Destroy methods concurrently on the cluster, Put call may set new values to the DMap.
func (*ClusterDMap) Expire ¶
Expire updates the expiry for the given key. It returns ErrKeyNotFound if the DB does not contain the key. It's thread-safe.
func (*ClusterDMap) Get ¶
func (dm *ClusterDMap) Get(ctx context.Context, key string) (*GetResponse, error)
Get gets the value for the given key. It returns ErrKeyNotFound if the DB does not contain the key. It's thread-safe. It is safe to modify the contents of the returned value. See GetResponse for the details.
func (*ClusterDMap) GetPut ¶
func (dm *ClusterDMap) GetPut(ctx context.Context, key string, value interface{}) (*GetResponse, error)
GetPut atomically sets the key to value and returns the old value stored at key. It returns nil if there is no previous value.
func (*ClusterDMap) Incr ¶
Incr atomically increments the key by delta. The return value is the new value after being incremented or an error.
func (*ClusterDMap) IncrByFloat ¶
IncrByFloat atomically increments the key by delta. The return value is the new value after being incremented or an error.
func (*ClusterDMap) Lock ¶
func (dm *ClusterDMap) Lock(ctx context.Context, key string, deadline time.Duration) (LockContext, error)
Lock sets a lock for the given key. Acquired lock is only for the key in this dmap.
It returns immediately if it acquires the lock for the given key. Otherwise, it waits until deadline.
You should know that the locks are approximate, and only to be used for non-critical purposes.
func (*ClusterDMap) LockWithTimeout ¶
func (dm *ClusterDMap) LockWithTimeout(ctx context.Context, key string, timeout, deadline time.Duration) (LockContext, error)
LockWithTimeout sets a lock for the given key. If the lock is still unreleased the end of given period of time, it automatically releases the lock. Acquired lock is only for the key in this DMap.
It returns immediately if it acquires the lock for the given key. Otherwise, it waits until deadline.
You should know that the locks are approximate, and only to be used for non-critical purposes.
func (*ClusterDMap) Pipeline ¶
func (dm *ClusterDMap) Pipeline(opts ...PipelineOption) (*DMapPipeline, error)
Pipeline is a mechanism to realise Redis Pipeline technique.
Pipelining is a technique to extremely speed up processing by packing operations to batches, send them at once to Redis and read a replies in a singe step. See https://redis.io/topics/pipelining
Pay attention, that Pipeline is not a transaction, so you can get unexpected results in case of big pipelines and small read/write timeouts. Redis client has retransmission logic in case of timeouts, pipeline can be retransmitted and commands can be executed more than once.
func (*ClusterDMap) Put ¶
func (dm *ClusterDMap) Put(ctx context.Context, key string, value interface{}, options ...PutOption) error
Put sets the value for the given key. It overwrites any previous value for that key, and it's thread-safe. The key has to be a string. value type is arbitrary. It is safe to modify the contents of the arguments after Put returns but not before.
func (*ClusterDMap) Scan ¶
func (dm *ClusterDMap) Scan(ctx context.Context, options ...ScanOption) (Iterator, error)
Scan returns an iterator to loop over the keys.
Available scan options:
* Count * Match
type ClusterIterator ¶
type ClusterIterator struct {
// contains filtered or unexported fields
}
ClusterIterator implements distributed query on DMaps.
func (*ClusterIterator) Close ¶
func (i *ClusterIterator) Close()
Close stops the iteration and releases allocated resources.
func (*ClusterIterator) Key ¶
func (i *ClusterIterator) Key() string
Key returns a key name from the distributed map.
func (*ClusterIterator) Next ¶
func (i *ClusterIterator) Next() bool
Next returns true if there is more key in the iterator implementation. Otherwise, it returns false
type ClusterLockContext ¶
type ClusterLockContext struct {
// contains filtered or unexported fields
}
type DMap ¶
type DMap interface { // Name exposes name of the DMap. Name() string // Put sets the value for the given key. It overwrites any previous value for // that key, and it's thread-safe. The key has to be a string. value type is arbitrary. // It is safe to modify the contents of the arguments after Put returns but not before. Put(ctx context.Context, key string, value interface{}, options ...PutOption) error // Get gets the value for the given key. It returns ErrKeyNotFound if the DB // does not contain the key. It's thread-safe. It is safe to modify the contents // of the returned value. See GetResponse for the details. Get(ctx context.Context, key string) (*GetResponse, error) // Delete deletes values for the given keys. Delete will not return error // if key doesn't exist. It's thread-safe. It is safe to modify the contents // of the argument after Delete returns. Delete(ctx context.Context, keys ...string) (int, error) // Incr atomically increments the key by delta. The return value is the new value // after being incremented or an error. Incr(ctx context.Context, key string, delta int) (int, error) // Decr atomically decrements the key by delta. The return value is the new value // after being decremented or an error. Decr(ctx context.Context, key string, delta int) (int, error) // GetPut atomically sets the key to value and returns the old value stored at key. It returns nil if there is no // previous value. GetPut(ctx context.Context, key string, value interface{}) (*GetResponse, error) // IncrByFloat atomically increments the key by delta. The return value is the new value // after being incremented or an error. IncrByFloat(ctx context.Context, key string, delta float64) (float64, error) // Expire updates the expiry for the given key. It returns ErrKeyNotFound if // the DB does not contain the key. It's thread-safe. Expire(ctx context.Context, key string, timeout time.Duration) error // Lock sets a lock for the given key. Acquired lock is only for the key in // this dmap. // // It returns immediately if it acquires the lock for the given key. Otherwise, // it waits until deadline. // // You should know that the locks are approximate, and only to be used for // non-critical purposes. Lock(ctx context.Context, key string, deadline time.Duration) (LockContext, error) // LockWithTimeout sets a lock for the given key. If the lock is still unreleased // the end of given period of time, // it automatically releases the lock. Acquired lock is only for the key in // this dmap. // // It returns immediately if it acquires the lock for the given key. Otherwise, // it waits until deadline. // // You should know that the locks are approximate, and only to be used for // non-critical purposes. LockWithTimeout(ctx context.Context, key string, timeout, deadline time.Duration) (LockContext, error) // Scan returns an iterator to loop over the keys. // // Available scan options: // // * Count // * Match Scan(ctx context.Context, options ...ScanOption) (Iterator, error) // Destroy flushes the given DMap on the cluster. You should know that there // is no global lock on DMaps. So if you call Put/PutEx and Destroy methods // concurrently on the cluster, Put call may set new values to the DMap. Destroy(ctx context.Context) error // Pipeline is a mechanism to realise Redis Pipeline technique. // // Pipelining is a technique to extremely speed up processing by packing // operations to batches, send them at once to Redis and read a replies in a // singe step. // See https://redis.io/topics/pipelining // // Pay attention, that Pipeline is not a transaction, so you can get unexpected // results in case of big pipelines and small read/write timeouts. // Redis client has retransmission logic in case of timeouts, pipeline // can be retransmitted and commands can be executed more than once. Pipeline(opts ...PipelineOption) (*DMapPipeline, error) }
DMap defines methods to access and manipulate distributed maps.
type DMapOption ¶
type DMapOption func(*dmapConfig)
DMapOption is a function for defining options to control behavior of distributed map instances.
func StorageEntryImplementation ¶
func StorageEntryImplementation(e func() storage.Entry) DMapOption
StorageEntryImplementation sets and encoder/decoder implementation for your choice of storage engine.
type DMapPipeline ¶
type DMapPipeline struct {
// contains filtered or unexported fields
}
DMapPipeline implements a pipeline for the following methods of the DMap API:
* Put * Get * Delete * Incr * Decr * GetPut * IncrByFloat
DMapPipeline enables batch operations on DMap data.
func (*DMapPipeline) Close ¶
func (dp *DMapPipeline) Close()
Close closes the pipeline and frees the allocated resources. You shouldn't try to reuse a closed pipeline.
func (*DMapPipeline) Decr ¶
func (dp *DMapPipeline) Decr(ctx context.Context, key string, delta int) (*FutureDecr, error)
Decr queues a Decr command. The parameters are identical to the DMap.Decr, but it returns FutureDecr to read the batched response.
func (*DMapPipeline) Delete ¶
func (dp *DMapPipeline) Delete(ctx context.Context, key string) *FutureDelete
Delete queues a Delete command. The parameters are identical to the DMap.Delete, but it returns FutureDelete to read the batched response.
func (*DMapPipeline) Discard ¶
func (dp *DMapPipeline) Discard() error
Discard discards the pipelined commands and resets all internal states. A pipeline can be reused after calling Discard.
func (*DMapPipeline) Exec ¶
func (dp *DMapPipeline) Exec(ctx context.Context) error
Exec executes all queued commands using one client-server roundtrip per partition.
func (*DMapPipeline) Expire ¶
func (dp *DMapPipeline) Expire(ctx context.Context, key string, timeout time.Duration) (*FutureExpire, error)
Expire queues an Expire command. The parameters are identical to the DMap.Expire, but it returns FutureExpire to read the batched response.
func (*DMapPipeline) Get ¶
func (dp *DMapPipeline) Get(ctx context.Context, key string) *FutureGet
Get queues a Get command. The parameters are identical to the DMap.Get, but it returns FutureGet to read the batched response.
func (*DMapPipeline) GetPut ¶
func (dp *DMapPipeline) GetPut(ctx context.Context, key string, value interface{}) (*FutureGetPut, error)
GetPut queues a GetPut command. The parameters are identical to the DMap.GetPut, but it returns FutureGetPut to read the batched response.
func (*DMapPipeline) Incr ¶
func (dp *DMapPipeline) Incr(ctx context.Context, key string, delta int) (*FutureIncr, error)
Incr queues an Incr command. The parameters are identical to the DMap.Incr, but it returns FutureIncr to read the batched response.
func (*DMapPipeline) IncrByFloat ¶
func (dp *DMapPipeline) IncrByFloat(ctx context.Context, key string, delta float64) (*FutureIncrByFloat, error)
IncrByFloat queues an IncrByFloat command. The parameters are identical to the DMap.IncrByFloat, but it returns FutureIncrByFloat to read the batched response.
type EmbeddedClient ¶
type EmbeddedClient struct {
// contains filtered or unexported fields
}
EmbeddedClient is an Olric client implementation for embedded-member scenario.
func (*EmbeddedClient) Close ¶
func (e *EmbeddedClient) Close(_ context.Context) error
Close stops background routines and frees allocated resources.
func (*EmbeddedClient) Members ¶
func (e *EmbeddedClient) Members(_ context.Context) ([]Member, error)
Members returns a thread-safe list of cluster members.
func (*EmbeddedClient) NewDMap ¶
func (e *EmbeddedClient) NewDMap(name string, options ...DMapOption) (DMap, error)
func (*EmbeddedClient) NewPubSub ¶
func (e *EmbeddedClient) NewPubSub(options ...PubSubOption) (*PubSub, error)
NewPubSub returns a new PubSub client with the given options.
func (*EmbeddedClient) Ping ¶
Ping sends a ping message to an Olric node. Returns PONG if message is empty, otherwise return a copy of the message as a bulk. This command is often used to test if a connection is still alive, or to measure latency.
func (*EmbeddedClient) RefreshMetadata ¶
func (e *EmbeddedClient) RefreshMetadata(_ context.Context) error
RefreshMetadata fetches a list of available members and the latest routing table version. It also closes stale clients, if there are any. EmbeddedClient has this method to implement the Client interface. It doesn't need to refresh metadata manually.
func (*EmbeddedClient) RoutingTable ¶
func (e *EmbeddedClient) RoutingTable(ctx context.Context) (RoutingTable, error)
RoutingTable returns the latest version of the routing table.
func (*EmbeddedClient) Stats ¶
func (e *EmbeddedClient) Stats(ctx context.Context, address string, options ...StatsOption) (stats.Stats, error)
Stats exposes some useful metrics to monitor an Olric node.
type EmbeddedDMap ¶
type EmbeddedDMap struct {
// contains filtered or unexported fields
}
EmbeddedDMap is an DMap client implementation for embedded-member scenario.
func (*EmbeddedDMap) Decr ¶
Decr atomically decrements the key by delta. The return value is the new value after being decremented or an error.
func (*EmbeddedDMap) Delete ¶
Delete deletes values for the given keys. Delete will not return error if key doesn't exist. It's thread-safe. It is safe to modify the contents of the argument after Delete returns.
func (*EmbeddedDMap) Destroy ¶
func (dm *EmbeddedDMap) Destroy(ctx context.Context) error
Destroy flushes the given DMap on the cluster. You should know that there is no global lock on DMaps. So if you call Put/PutEx and Destroy methods concurrently on the cluster, Put call may set new values to the DMap.
func (*EmbeddedDMap) Expire ¶
Expire updates the expiry for the given key. It returns ErrKeyNotFound if the DB does not contain the key. It's thread-safe.
func (*EmbeddedDMap) Get ¶
func (dm *EmbeddedDMap) Get(ctx context.Context, key string) (*GetResponse, error)
Get gets the value for the given key. It returns ErrKeyNotFound if the DB does not contain the key. It's thread-safe. It is safe to modify the contents of the returned value. See GetResponse for the details.
func (*EmbeddedDMap) GetPut ¶
func (dm *EmbeddedDMap) GetPut(ctx context.Context, key string, value interface{}) (*GetResponse, error)
GetPut atomically sets the key to value and returns the old value stored at key. It returns nil if there is no previous value.
func (*EmbeddedDMap) Incr ¶
Incr atomically increments the key by delta. The return value is the new value after being incremented or an error.
func (*EmbeddedDMap) IncrByFloat ¶
func (dm *EmbeddedDMap) IncrByFloat(ctx context.Context, key string, delta float64) (float64, error)
IncrByFloat atomically increments the key by delta. The return value is the new value after being incremented or an error.
func (*EmbeddedDMap) Lock ¶
func (dm *EmbeddedDMap) Lock(ctx context.Context, key string, deadline time.Duration) (LockContext, error)
Lock sets a lock for the given key. Acquired lock is only for the key in this dmap.
It returns immediately if it acquires the lock for the given key. Otherwise, it waits until deadline.
You should know that the locks are approximate, and only to be used for non-critical purposes.
func (*EmbeddedDMap) LockWithTimeout ¶
func (dm *EmbeddedDMap) LockWithTimeout(ctx context.Context, key string, timeout, deadline time.Duration) (LockContext, error)
LockWithTimeout sets a lock for the given key. If the lock is still unreleased the end of given period of time, it automatically releases the lock. Acquired lock is only for the key in this dmap.
It returns immediately if it acquires the lock for the given key. Otherwise, it waits until deadline.
You should know that the locks are approximate, and only to be used for non-critical purposes.
func (*EmbeddedDMap) Pipeline ¶
func (dm *EmbeddedDMap) Pipeline(opts ...PipelineOption) (*DMapPipeline, error)
Pipeline is a mechanism to realise Redis Pipeline technique.
Pipelining is a technique to extremely speed up processing by packing operations to batches, send them at once to Redis and read a replies in a singe step. See https://redis.io/topics/pipelining
Pay attention, that Pipeline is not a transaction, so you can get unexpected results in case of big pipelines and small read/write timeouts. Redis client has retransmission logic in case of timeouts, pipeline can be retransmitted and commands can be executed more than once.
func (*EmbeddedDMap) Put ¶
func (dm *EmbeddedDMap) Put(ctx context.Context, key string, value interface{}, options ...PutOption) error
Put sets the value for the given key. It overwrites any previous value for that key, and it's thread-safe. The key has to be a string. value type is arbitrary. It is safe to modify the contents of the arguments after Put returns but not before.
func (*EmbeddedDMap) Scan ¶
func (dm *EmbeddedDMap) Scan(ctx context.Context, options ...ScanOption) (Iterator, error)
Scan returns an iterator to loop over the keys.
Available scan options:
* Count * Match
type EmbeddedIterator ¶
type EmbeddedIterator struct {
// contains filtered or unexported fields
}
EmbeddedIterator implements distributed query on DMaps.
func (*EmbeddedIterator) Close ¶
func (e *EmbeddedIterator) Close()
Close stops the iteration and releases allocated resources.
func (*EmbeddedIterator) Key ¶
func (e *EmbeddedIterator) Key() string
Key returns a key name from the distributed map.
func (*EmbeddedIterator) Next ¶
func (e *EmbeddedIterator) Next() bool
Next returns true if there is more key in the iterator implementation. Otherwise, it returns false.
type EmbeddedLockContext ¶
type EmbeddedLockContext struct {
// contains filtered or unexported fields
}
EmbeddedLockContext is returned by Lock and LockWithTimeout methods. It should be stored in a proper way to release the lock.
type FutureDecr ¶
type FutureDecr struct {
// contains filtered or unexported fields
}
FutureDecr is used to read the result of a pipelined Decr command.
func (*FutureDecr) Result ¶
func (f *FutureDecr) Result() (int, error)
Result returns a response for the pipelined Decr command.
type FutureDelete ¶
type FutureDelete struct {
// contains filtered or unexported fields
}
FutureDelete is used to read the result of a pipelined Delete command.
func (*FutureDelete) Result ¶
func (f *FutureDelete) Result() (int, error)
Result returns a response for the pipelined Delete command.
type FutureExpire ¶
type FutureExpire struct {
// contains filtered or unexported fields
}
FutureExpire is used to read the result of a pipelined Expire command.
func (*FutureExpire) Result ¶
func (f *FutureExpire) Result() error
Result returns a response for the pipelined Expire command.
type FutureGet ¶
type FutureGet struct {
// contains filtered or unexported fields
}
FutureGet is used to read result of a pipelined Get command.
func (*FutureGet) Result ¶
func (f *FutureGet) Result() (*GetResponse, error)
Result returns a response for the pipelined Get command.
type FutureGetPut ¶
type FutureGetPut struct {
// contains filtered or unexported fields
}
FutureGetPut is used to read the result of a pipelined GetPut command.
func (*FutureGetPut) Result ¶
func (f *FutureGetPut) Result() (*GetResponse, error)
Result returns a response for the pipelined GetPut command.
type FutureIncr ¶
type FutureIncr struct {
// contains filtered or unexported fields
}
FutureIncr is used to read the result of a pipelined Incr command.
func (*FutureIncr) Result ¶
func (f *FutureIncr) Result() (int, error)
Result returns a response for the pipelined Incr command.
type FutureIncrByFloat ¶
type FutureIncrByFloat struct {
// contains filtered or unexported fields
}
FutureIncrByFloat is used to read the result of a pipelined IncrByFloat command.
func (*FutureIncrByFloat) Result ¶
func (f *FutureIncrByFloat) Result() (float64, error)
Result returns a response for the pipelined IncrByFloat command.
type FuturePut ¶
type FuturePut struct {
// contains filtered or unexported fields
}
FuturePut is used to read the result of a pipelined Put command.
type GetResponse ¶
type GetResponse struct {
// contains filtered or unexported fields
}
func (*GetResponse) Bool ¶
func (g *GetResponse) Bool() (bool, error)
func (*GetResponse) Byte ¶
func (g *GetResponse) Byte() ([]byte, error)
func (*GetResponse) Float32 ¶
func (g *GetResponse) Float32() (float32, error)
func (*GetResponse) Float64 ¶
func (g *GetResponse) Float64() (float64, error)
func (*GetResponse) Int ¶
func (g *GetResponse) Int() (int, error)
func (*GetResponse) Int16 ¶
func (g *GetResponse) Int16() (int16, error)
func (*GetResponse) Int32 ¶
func (g *GetResponse) Int32() (int32, error)
func (*GetResponse) Int64 ¶
func (g *GetResponse) Int64() (int64, error)
func (*GetResponse) Int8 ¶
func (g *GetResponse) Int8() (int8, error)
func (*GetResponse) Scan ¶
func (g *GetResponse) Scan(v interface{}) error
func (*GetResponse) String ¶
func (g *GetResponse) String() (string, error)
func (*GetResponse) TTL ¶
func (g *GetResponse) TTL() int64
func (*GetResponse) Timestamp ¶
func (g *GetResponse) Timestamp() int64
func (*GetResponse) Uint ¶
func (g *GetResponse) Uint() (uint, error)
func (*GetResponse) Uint16 ¶
func (g *GetResponse) Uint16() (uint16, error)
func (*GetResponse) Uint32 ¶
func (g *GetResponse) Uint32() (uint32, error)
func (*GetResponse) Uint64 ¶
func (g *GetResponse) Uint64() (uint64, error)
func (*GetResponse) Uint8 ¶
func (g *GetResponse) Uint8() (uint8, error)
type Iterator ¶
type Iterator interface { // Next returns true if there is more key in the iterator implementation. // Otherwise, it returns false. Next() bool // Key returns a key name from the distributed map. Key() string // Close stops the iteration and releases allocated resources. Close() }
Iterator defines an interface to implement iterators on the distributed maps.
type LockContext ¶
type LockContext interface { // Unlock releases an acquired lock for the given key. It returns ErrNoSuchLock // if there is no lock for the given key. Unlock(ctx context.Context) error // Lease sets or updates the timeout of the acquired lock for the given key. // It returns ErrNoSuchLock if there is no lock for the given key. Lease(ctx context.Context, duration time.Duration) error }
LockContext interface defines methods to manage locks on distributed maps.
type Member ¶
type Member struct { // Member name in the cluster. It's also host:port of the node. Name string // ID of the Member in the cluster. Hash of Name and Birthdate of the member ID uint64 // Birthdate of the member in nanoseconds. Birthdate int64 // Role of the member in the cluster. There is only one coordinator member // in a healthy cluster. Coordinator bool }
Member denotes a member of the Olric cluster.
type Olric ¶
type Olric struct {
// contains filtered or unexported fields
}
Olric implements a distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service.
func (*Olric) NewEmbeddedClient ¶
func (db *Olric) NewEmbeddedClient() *EmbeddedClient
NewEmbeddedClient creates and returns a new EmbeddedClient instance.
type PipelineOption ¶
type PipelineOption func(pipeline *DMapPipeline)
PipelineOption is a function for defining options to control behavior of the Pipeline command.
func PipelineConcurrency ¶
func PipelineConcurrency(concurrency int) PipelineOption
PipelineConcurrency is a PipelineOption controlling the number of concurrent goroutines.
type PubSub ¶
type PubSub struct {
// contains filtered or unexported fields
}
func (*PubSub) PSubscribe ¶
func (*PubSub) PubSubChannels ¶
func (*PubSub) PubSubNumSub ¶
type PubSubOption ¶
type PubSubOption func(option *pubsubConfig)
PubSubOption is a function for defining options to control behavior of the Publish-Subscribe service.
func ToAddress ¶
func ToAddress(addr string) PubSubOption
ToAddress is a PubSubOption for using a specific cluster member to publish messages to a channel.
type PutOption ¶
PutOption is a function for define options to control behavior of the Put command.
type RoutingTable ¶
type ScanOption ¶
type ScanOption func(*dmap.ScanConfig)
ScanOption is a function for defining options to control behavior of the SCAN command.
func Count ¶
func Count(c int) ScanOption
Count is the user specified the amount of work that should be done at every call in order to retrieve elements from the distributed map. This is just a hint for the implementation, however generally speaking this is what you could expect most of the time from the implementation. The default value is 10.
func Match ¶
func Match(s string) ScanOption
Match is used for using regular expressions on keys. See https://pkg.go.dev/regexp
type StatsOption ¶
type StatsOption func(*statsConfig)
StatsOption is a function for defining options to control behavior of the STATS command.
func CollectRuntime ¶
func CollectRuntime() StatsOption
CollectRuntime is a StatsOption for collecting Go runtime statistics from a cluster member.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
internal
|
|
discovery
Package discovery provides a basic memberlist integration.
|
Package discovery provides a basic memberlist integration. |
kvstore
Package kvstore implements a GC friendly in-memory storage engine by using built-in maps and byte slices.
|
Package kvstore implements a GC friendly in-memory storage engine by using built-in maps and byte slices. |
locker
Package locker provides a mechanism for creating finer-grained locking to help free up more global locks to handle other tasks.
|
Package locker provides a mechanism for creating finer-grained locking to help free up more global locks to handle other tasks. |
pkg
|
|
flog
Package flog is a simple wrapper around Golang's log package which adds verbosity support.
|
Package flog is a simple wrapper around Golang's log package which adds verbosity support. |
service_discovery
Package service_discovery provides ServiceDiscovery interface for plugins
|
Package service_discovery provides ServiceDiscovery interface for plugins |
Package stats exposes internal data structures for Stat command
|
Package stats exposes internal data structures for Stat command |