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.5.7"
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("cannot be reached cluster quorum to operate") // 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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
type ClusterClient struct {
// contains filtered or unexported fields
}
func NewClusterClient ¶ added in v0.5.0
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 ¶ added in v0.5.0
func (cl *ClusterClient) Close(ctx context.Context) error
Close stops background routines and frees allocated resources.
func (*ClusterClient) Members ¶ added in v0.5.0
func (cl *ClusterClient) Members(ctx context.Context) ([]Member, error)
Members returns a thread-safe list of cluster members.
func (*ClusterClient) NewDMap ¶ added in v0.5.0
func (cl *ClusterClient) NewDMap(name string, options ...DMapOption) (DMap, error)
NewDMap returns a new DMap client with the given options.
func (*ClusterClient) NewPubSub ¶ added in v0.5.0
func (cl *ClusterClient) NewPubSub(options ...PubSubOption) (*PubSub, error)
NewPubSub returns a new PubSub client with the given options.
func (*ClusterClient) Ping ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
func (cl *ClusterClient) RoutingTable(ctx context.Context) (RoutingTable, error)
RoutingTable returns the latest version of the routing table.
func (*ClusterClient) Stats ¶ added in v0.5.0
func (cl *ClusterClient) Stats(ctx context.Context, address string, options ...StatsOption) (stats.Stats, error)
Stats returns stats.Stats with the given options.
type ClusterClientOption ¶ added in v0.5.0
type ClusterClientOption func(c *clusterClientConfig)
func WithConfig ¶ added in v0.5.0
func WithConfig(c *config.Client) ClusterClientOption
func WithHasher ¶ added in v0.5.0
func WithHasher(h hasher.Hasher) ClusterClientOption
func WithLogger ¶ added in v0.5.0
func WithLogger(l *log.Logger) ClusterClientOption
func WithRoutingTableFetchInterval ¶ added in v0.5.2
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 ¶ added in v0.5.0
type ClusterDMap struct {
// contains filtered or unexported fields
}
ClusterDMap implements a client for DMaps.
func (*ClusterDMap) Decr ¶ added in v0.5.0
Decr atomically decrements the key by delta. The return value is the new value after being decremented or an error.
func (*ClusterDMap) Delete ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
Incr atomically increments the key by delta. The return value is the new value after being incremented or an error.
func (*ClusterDMap) IncrByFloat ¶ added in v0.5.0
IncrByFloat atomically increments the key by delta. The return value is the new value after being incremented or an error.
func (*ClusterDMap) Lock ¶ added in v0.5.0
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 ¶ added in v0.5.0
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) Name ¶ added in v0.5.0
func (dm *ClusterDMap) Name() string
Name exposes name of the DMap.
func (*ClusterDMap) Pipeline ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
type ClusterIterator struct {
// contains filtered or unexported fields
}
ClusterIterator implements distributed query on DMaps.
func (*ClusterIterator) Close ¶ added in v0.5.0
func (i *ClusterIterator) Close()
Close stops the iteration and releases allocated resources.
func (*ClusterIterator) Key ¶ added in v0.5.0
func (i *ClusterIterator) Key() string
Key returns a key name from the distributed map.
func (*ClusterIterator) Next ¶ added in v0.5.0
func (i *ClusterIterator) Next() bool
Next returns true if there is more key in the iterator implementation. Otherwise, it returns false
type ClusterLockContext ¶ added in v0.5.0
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 ¶ added in v0.5.0
type DMapOption func(*dmapConfig)
DMapOption is a function for defining options to control behavior of distributed map instances.
func StorageEntryImplementation ¶ added in v0.5.0
func StorageEntryImplementation(e func() storage.Entry) DMapOption
StorageEntryImplementation sets and encoder/decoder implementation for your choice of storage engine.
type DMapPipeline ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
func (dp *DMapPipeline) Exec(ctx context.Context) error
Exec executes all queued commands using one client-server roundtrip per partition.
func (*DMapPipeline) Expire ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
type EmbeddedClient struct {
// contains filtered or unexported fields
}
EmbeddedClient is an Olric client implementation for embedded-member scenario.
func (*EmbeddedClient) Close ¶ added in v0.5.0
func (e *EmbeddedClient) Close(_ context.Context) error
Close stops background routines and frees allocated resources.
func (*EmbeddedClient) Members ¶ added in v0.5.0
func (e *EmbeddedClient) Members(_ context.Context) ([]Member, error)
Members returns a thread-safe list of cluster members.
func (*EmbeddedClient) NewDMap ¶ added in v0.5.0
func (e *EmbeddedClient) NewDMap(name string, options ...DMapOption) (DMap, error)
func (*EmbeddedClient) NewPubSub ¶ added in v0.5.0
func (e *EmbeddedClient) NewPubSub(options ...PubSubOption) (*PubSub, error)
NewPubSub returns a new PubSub client with the given options.
func (*EmbeddedClient) Ping ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
func (e *EmbeddedClient) RoutingTable(ctx context.Context) (RoutingTable, error)
RoutingTable returns the latest version of the routing table.
func (*EmbeddedClient) Stats ¶ added in v0.5.0
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 ¶ added in v0.5.0
type EmbeddedDMap struct {
// contains filtered or unexported fields
}
EmbeddedDMap is an DMap client implementation for embedded-member scenario.
func (*EmbeddedDMap) Decr ¶ added in v0.5.0
Decr atomically decrements the key by delta. The return value is the new value after being decremented or an error.
func (*EmbeddedDMap) Delete ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
Incr atomically increments the key by delta. The return value is the new value after being incremented or an error.
func (*EmbeddedDMap) IncrByFloat ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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) Name ¶ added in v0.5.0
func (dm *EmbeddedDMap) Name() string
Name exposes name of the DMap.
func (*EmbeddedDMap) Pipeline ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
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 ¶ added in v0.5.0
type EmbeddedIterator struct {
// contains filtered or unexported fields
}
EmbeddedIterator implements distributed query on DMaps.
func (*EmbeddedIterator) Close ¶ added in v0.5.0
func (e *EmbeddedIterator) Close()
Close stops the iteration and releases allocated resources.
func (*EmbeddedIterator) Key ¶ added in v0.5.0
func (e *EmbeddedIterator) Key() string
Key returns a key name from the distributed map.
func (*EmbeddedIterator) Next ¶ added in v0.5.0
func (e *EmbeddedIterator) Next() bool
Next returns true if there is more key in the iterator implementation. Otherwise, it returns false.
type EmbeddedLockContext ¶ added in v0.5.0
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 ¶ added in v0.5.0
type FutureDecr struct {
// contains filtered or unexported fields
}
FutureDecr is used to read the result of a pipelined Decr command.
func (*FutureDecr) Result ¶ added in v0.5.0
func (f *FutureDecr) Result() (int, error)
Result returns a response for the pipelined Decr command.
type FutureDelete ¶ added in v0.5.0
type FutureDelete struct {
// contains filtered or unexported fields
}
FutureDelete is used to read the result of a pipelined Delete command.
func (*FutureDelete) Result ¶ added in v0.5.0
func (f *FutureDelete) Result() (int, error)
Result returns a response for the pipelined Delete command.
type FutureExpire ¶ added in v0.5.0
type FutureExpire struct {
// contains filtered or unexported fields
}
FutureExpire is used to read the result of a pipelined Expire command.
func (*FutureExpire) Result ¶ added in v0.5.0
func (f *FutureExpire) Result() error
Result returns a response for the pipelined Expire command.
type FutureGet ¶ added in v0.5.0
type FutureGet struct {
// contains filtered or unexported fields
}
FutureGet is used to read result of a pipelined Get command.
func (*FutureGet) Result ¶ added in v0.5.0
func (f *FutureGet) Result() (*GetResponse, error)
Result returns a response for the pipelined Get command.
type FutureGetPut ¶ added in v0.5.0
type FutureGetPut struct {
// contains filtered or unexported fields
}
FutureGetPut is used to read the result of a pipelined GetPut command.
func (*FutureGetPut) Result ¶ added in v0.5.0
func (f *FutureGetPut) Result() (*GetResponse, error)
Result returns a response for the pipelined GetPut command.
type FutureIncr ¶ added in v0.5.0
type FutureIncr struct {
// contains filtered or unexported fields
}
FutureIncr is used to read the result of a pipelined Incr command.
func (*FutureIncr) Result ¶ added in v0.5.0
func (f *FutureIncr) Result() (int, error)
Result returns a response for the pipelined Incr command.
type FutureIncrByFloat ¶ added in v0.5.0
type FutureIncrByFloat struct {
// contains filtered or unexported fields
}
FutureIncrByFloat is used to read the result of a pipelined IncrByFloat command.
func (*FutureIncrByFloat) Result ¶ added in v0.5.0
func (f *FutureIncrByFloat) Result() (float64, error)
Result returns a response for the pipelined IncrByFloat command.
type FuturePut ¶ added in v0.5.0
type FuturePut struct {
// contains filtered or unexported fields
}
FuturePut is used to read the result of a pipelined Put command.
type GetResponse ¶ added in v0.5.0
type GetResponse struct {
// contains filtered or unexported fields
}
func (*GetResponse) Bool ¶ added in v0.5.0
func (g *GetResponse) Bool() (bool, error)
func (*GetResponse) Byte ¶ added in v0.5.0
func (g *GetResponse) Byte() ([]byte, error)
func (*GetResponse) Duration ¶ added in v0.5.0
func (g *GetResponse) Duration() (time.Duration, error)
func (*GetResponse) Float32 ¶ added in v0.5.0
func (g *GetResponse) Float32() (float32, error)
func (*GetResponse) Float64 ¶ added in v0.5.0
func (g *GetResponse) Float64() (float64, error)
func (*GetResponse) Int ¶ added in v0.5.0
func (g *GetResponse) Int() (int, error)
func (*GetResponse) Int16 ¶ added in v0.5.0
func (g *GetResponse) Int16() (int16, error)
func (*GetResponse) Int32 ¶ added in v0.5.0
func (g *GetResponse) Int32() (int32, error)
func (*GetResponse) Int64 ¶ added in v0.5.0
func (g *GetResponse) Int64() (int64, error)
func (*GetResponse) Int8 ¶ added in v0.5.0
func (g *GetResponse) Int8() (int8, error)
func (*GetResponse) Scan ¶ added in v0.5.0
func (g *GetResponse) Scan(v interface{}) error
func (*GetResponse) String ¶ added in v0.5.0
func (g *GetResponse) String() (string, error)
func (*GetResponse) TTL ¶ added in v0.5.0
func (g *GetResponse) TTL() int64
func (*GetResponse) Timestamp ¶ added in v0.5.0
func (g *GetResponse) Timestamp() int64
func (*GetResponse) Uint ¶ added in v0.5.0
func (g *GetResponse) Uint() (uint, error)
func (*GetResponse) Uint16 ¶ added in v0.5.0
func (g *GetResponse) Uint16() (uint16, error)
func (*GetResponse) Uint32 ¶ added in v0.5.0
func (g *GetResponse) Uint32() (uint32, error)
func (*GetResponse) Uint64 ¶ added in v0.5.0
func (g *GetResponse) Uint64() (uint64, error)
func (*GetResponse) Uint8 ¶ added in v0.5.0
func (g *GetResponse) Uint8() (uint8, error)
type Iterator ¶ added in v0.5.0
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 ¶ added in v0.2.0
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 ¶ added in v0.5.0
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 ¶ added in v0.2.0
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 ¶ added in v0.5.0
func (db *Olric) NewEmbeddedClient() *EmbeddedClient
NewEmbeddedClient creates and returns a new EmbeddedClient instance.
type PipelineOption ¶ added in v0.5.1
type PipelineOption func(pipeline *DMapPipeline)
PipelineOption is a function for defining options to control behavior of the Pipeline command.
func PipelineConcurrency ¶ added in v0.5.1
func PipelineConcurrency(concurrency int) PipelineOption
PipelineConcurrency is a PipelineOption controlling the number of concurrent goroutines.
type PubSub ¶ added in v0.5.0
type PubSub struct {
// contains filtered or unexported fields
}
func (*PubSub) PSubscribe ¶ added in v0.5.0
func (*PubSub) PubSubChannels ¶ added in v0.5.0
func (*PubSub) PubSubNumPat ¶ added in v0.5.0
func (*PubSub) PubSubNumSub ¶ added in v0.5.0
type PubSubOption ¶ added in v0.5.0
type PubSubOption func(option *pubsubConfig)
PubSubOption is a function for defining options to control behavior of the Publish-Subscribe service.
func ToAddress ¶ added in v0.5.0
func ToAddress(addr string) PubSubOption
ToAddress is a PubSubOption for using a specific cluster member to publish messages to a channel.
type PutOption ¶ added in v0.5.0
PutOption is a function for define options to control behavior of the Put command.
func EXAT ¶ added in v0.5.0
EXAT sets the specified Unix time at which the key will expire, in seconds.
type RoutingTable ¶ added in v0.5.0
type ScanOption ¶ added in v0.5.0
type ScanOption func(*dmap.ScanConfig)
ScanOption is a function for defining options to control behavior of the SCAN command.
func Count ¶ added in v0.5.0
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 ¶ added in v0.5.0
func Match(s string) ScanOption
Match is used for using regular expressions on keys. See https://pkg.go.dev/regexp
type StatsOption ¶ added in v0.4.0
type StatsOption func(*statsConfig)
StatsOption is a function for defining options to control behavior of the STATS command.
func CollectRuntime ¶ added in v0.4.0
func CollectRuntime() StatsOption
CollectRuntime is a StatsOption for collecting Go runtime statistics from a cluster member.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
olricd/server
Package server provides a standalone server implementation for Olric
|
Package server provides a standalone server implementation for Olric |
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 |