Documentation ¶
Overview ¶
Package client implements a Golang client to access an Olric cluster from outside.
Index ¶
- type Client
- type Config
- type Cursor
- type DMap
- func (d *DMap) Decr(key string, delta int) (int, error)
- func (d *DMap) Delete(key string) error
- func (d *DMap) Destroy() error
- func (d *DMap) Expire(key string, timeout time.Duration) error
- func (d *DMap) Get(key string) (interface{}, error)
- func (d *DMap) GetPut(key string, value interface{}) (interface{}, error)
- func (d *DMap) Incr(key string, delta int) (int, error)
- func (d *DMap) Lock(key string, deadline time.Duration) (*LockContext, error)
- func (d *DMap) LockWithTimeout(key string, timeout, deadline time.Duration) (*LockContext, error)
- func (d *DMap) Put(key string, value interface{}) error
- func (d *DMap) PutEx(key string, value interface{}, timeout time.Duration) error
- func (d *DMap) PutIf(key string, value interface{}, flags int16) error
- func (d *DMap) PutIfEx(key string, value interface{}, timeout time.Duration, flags int16) error
- func (d *DMap) Query(q query.M) (*Cursor, error)
- type DTopic
- type LockContext
- type Pipeline
- func (p *Pipeline) Decr(dmap, key string, delta int) error
- func (p *Pipeline) Delete(dmap, key string) error
- func (p *Pipeline) Destroy(dmap string) error
- func (p *Pipeline) Expire(dmap, key string, timeout time.Duration) error
- func (p *Pipeline) Flush() ([]PipelineResponse, error)
- func (p *Pipeline) Get(dmap, key string) error
- func (p *Pipeline) GetPut(dmap, key string, value interface{}) error
- func (p *Pipeline) Incr(dmap, key string, delta int) error
- func (p *Pipeline) Put(dmap, key string, value interface{}) error
- func (p *Pipeline) PutEx(dmap, key string, value interface{}, timeout time.Duration) error
- func (p *Pipeline) PutIf(dmap, key string, value interface{}, flags int16) error
- func (p *Pipeline) PutIfEx(dmap, key string, value interface{}, timeout time.Duration, flags int16) error
- type PipelineResponse
- func (pr *PipelineResponse) Decr() (int, error)
- func (pr *PipelineResponse) Delete() error
- func (pr *PipelineResponse) Destroy() error
- func (pr *PipelineResponse) Expire() error
- func (pr *PipelineResponse) Get() (interface{}, error)
- func (pr *PipelineResponse) GetPut() (interface{}, error)
- func (pr *PipelineResponse) Incr() (int, error)
- func (pr *PipelineResponse) Operation() string
- func (pr *PipelineResponse) Put() error
- func (pr *PipelineResponse) PutEx() error
- func (pr *PipelineResponse) PutIf() error
- func (pr *PipelineResponse) PutIfEx() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements Go client of Olric Binary Protocol and its methods.
func (*Client) Close ¶
func (c *Client) Close()
Close cancels underlying context and cancels ongoing requests.
func (*Client) NewDMap ¶ added in v0.2.0
NewDMap creates and returns a new dmap instance to access DMaps on the cluster.
func (*Client) NewDTopic ¶ added in v0.3.0
NewDTopic returns a new distributed topic instance. Parameters:
- name: DTopic name.
- concurrency: Maximum number of concurrently processing DTopic messages.
- flag: Any flag to control DTopic behaviour.
Flags for delivery options:
- UnorderedDelivery: Messages are delivered in random order. It's good to distribute independent events in a distributed system.
- OrderedDelivery: Messages are delivered in order. Not implemented yet.
func (*Client) NewPipeline ¶ added in v0.2.0
NewPipeline returns a new Pipeline.
type Config ¶ added in v0.2.0
type Config struct { Addrs []string Serializer serializer.Serializer DialTimeout time.Duration KeepAlive time.Duration MaxConn int MaxListenersPerStream int }
Config includes configuration parameters for the Client.
type Cursor ¶ added in v0.2.0
type Cursor struct {
// contains filtered or unexported fields
}
Cursor implements distributed query on DMaps. Call Cursor.Range to iterate over query results.
type DMap ¶ added in v0.2.0
type DMap struct { *Client // contains filtered or unexported fields }
dmap provides methods to access distributed maps on Olric cluster.
func (*DMap) Decr ¶ added in v0.2.0
Decr atomically decrements key by delta. The return value is the new value after being decremented or an error.
func (*DMap) Delete ¶ added in v0.2.0
Delete deletes the value for the given key. 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 (*DMap) Destroy ¶ added in v0.2.0
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/PutIf/PutIfEx and Destroy methods concurrently on the cluster, those calls may set new values to the dmap.
func (*DMap) Expire ¶ added in v0.2.0
Expire updates the expiry for the given key. It returns ErrKeyNotFound if the DB does not contains the key. It's thread-safe.
func (*DMap) Get ¶ added in v0.2.0
Get gets the value for the given key. It returns ErrKeyNotFound if the DB does not contains the key. It's thread-safe. It is safe to modify the contents of the returned value. It is safe to modify the contents of the argument after Get returns.
func (*DMap) GetPut ¶ added in v0.2.0
GetPut atomically sets key to value and returns the old value stored at key.
func (*DMap) Incr ¶ added in v0.2.0
Incr atomically increments key by delta. The return value is the new value after being incremented or an error.
func (*DMap) Lock ¶ added in v0.2.0
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 (*DMap) LockWithTimeout ¶ added in v0.2.0
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 (*DMap) Put ¶ added in v0.2.0
Put sets the value for the given key. It overwrites any previous value for that key and it's thread-safe. It is safe to modify the contents of the arguments after Put returns but not before.
func (*DMap) PutEx ¶ added in v0.2.0
PutEx sets the value for the given key with TTL. It overwrites any previous value for that key. It's thread-safe. It is safe to modify the contents of the arguments after Put returns but not before.
func (*DMap) PutIf ¶ added in v0.2.0
PutIf sets the value for the given key. It overwrites any previous value for that key and it's thread-safe. It is safe to modify the contents of the arguments after PutIf returns but not before. Flag argument currently has two different options:
olric.IfNotFound: Only set the key if it does not already exist. It returns olric.ErrFound if the key already exist.
olric.IfFound: Only set the key if it already exist. It returns olric.ErrKeyNotFound if the key does not exist.
func (*DMap) PutIfEx ¶ added in v0.2.0
PutIfEx sets the value for the given key with TTL. It overwrites any previous value for that key. It's thread-safe. It is safe to modify the contents of the arguments after PutIfEx returns but not before. Flag argument currently has two different options:
olric.IfNotFound: Only set the key if it does not already exist. It returns olric.ErrFound if the key already exist.
olric.IfFound: Only set the key if it already exist. It returns olric.ErrKeyNotFound if the key does not exist.
func (*DMap) Query ¶ added in v0.2.0
Query runs a distributed query on a dmap instance. Olric supports a very simple query DSL and now, it only scans keys. The query DSL has very few keywords:
$onKey: Runs the given query on keys or manages options on keys for a given query.
$onValue: Runs the given query on values or manages options on values for a given query.
$options: Useful to modify data returned from a query
Keywords for $options:
$ignore: Ignores a value.
A distributed query looks like the following:
query.M{ "$onKey": query.M{ "$regexMatch": "^even:", "$options": query.M{ "$onValue": query.M{ "$ignore": true, }, }, }, }
This query finds the keys starts with "even:", drops the values and returns only keys. If you also want to retrieve the values, just remove the $options directive:
query.M{ "$onKey": query.M{ "$regexMatch": "^even:", }, }
In order to iterate over all the keys:
query.M{ "$onKey": query.M{ "$regexMatch": "", }, }
Query function returns a cursor which has Range and Close methods. Please take look at the Range function for further info.
type DTopic ¶ added in v0.3.0
type DTopic struct { *Client // contains filtered or unexported fields }
DTopic denotes a distributed topic instance in the cluster.
func (*DTopic) AddListener ¶ added in v0.3.0
func (dt *DTopic) AddListener(f func(olric.DTopicMessage)) (uint64, error)
AddListener adds a new listener for the topic. Returns a listener ID or a non-nil error. The callback functions for this DTopic are run by parallel.
func (*DTopic) Destroy ¶ added in v0.3.0
Destroy a DTopic from the cluster. It stops background goroutines and releases underlying data structures.
func (*DTopic) Publish ¶ added in v0.3.0
Publish sends a message to the given topic. It accepts any serializable type as message.
func (*DTopic) RemoveListener ¶ added in v0.3.0
RemoveListener removes a listener with the given listenerID.
type LockContext ¶ added in v0.2.0
type LockContext struct {
// contains filtered or unexported fields
}
LockContext is returned by Lock and LockWithTimeout methods. It should be stored in a proper way to release the lock.
func (*LockContext) Unlock ¶ added in v0.2.0
func (l *LockContext) Unlock() error
Unlock releases an acquired lock for the given key. It returns olric.ErrNoSuchLock if there is no lock for the given key.
type Pipeline ¶ added in v0.2.0
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline implements pipelining feature for Olric Binary Protocol. It enables to send multiple commands to the server without waiting for the replies at all, and finally read the replies in a single step. All methods are thread-safe. So you can call them in different goroutines safely.
func (*Pipeline) Decr ¶ added in v0.2.0
Decr appends a Decr command to the underlying buffer with the given parameters.
func (*Pipeline) Delete ¶ added in v0.2.0
Delete appends a Delete command to the underlying buffer with the given parameters.
func (*Pipeline) Destroy ¶ added in v0.2.0
Destroy appends a Destroy command to the underlying buffer with the given parameters.
func (*Pipeline) Expire ¶ added in v0.2.0
Expire updates the expiry for the given key. It returns ErrKeyNotFound if the DB does not contains the key. It's thread-safe.
func (*Pipeline) Flush ¶ added in v0.2.0
func (p *Pipeline) Flush() ([]PipelineResponse, error)
Flush flushes all the commands to the server using a single write call.
func (*Pipeline) Get ¶ added in v0.2.0
Get appends a Get command to the underlying buffer with the given parameters.
func (*Pipeline) GetPut ¶ added in v0.2.0
GetPut appends a GetPut command to the underlying buffer with the given parameters.
func (*Pipeline) Incr ¶ added in v0.2.0
Incr appends an Incr command to the underlying buffer with the given parameters.
func (*Pipeline) Put ¶ added in v0.2.0
Put appends a Put command to the underlying buffer with the given parameters.
func (*Pipeline) PutEx ¶ added in v0.2.0
PutEx appends a PutEx command to the underlying buffer with the given parameters.
func (*Pipeline) PutIf ¶ added in v0.2.0
PutIf appends a PutIf command to the underlying buffer.
Flag argument currently has two different options:
olric.IfNotFound: Only set the key if it does not already exist. It returns olric.ErrFound if the key already exist.
olric.IfFound: Only set the key if it already exist. It returns olric.ErrKeyNotFound if the key does not exist.
func (*Pipeline) PutIfEx ¶ added in v0.2.0
func (p *Pipeline) PutIfEx(dmap, key string, value interface{}, timeout time.Duration, flags int16) error
PutIfEx appends a PutIfEx command to the underlying buffer.
Flag argument currently has two different options:
olric.IfNotFound: Only set the key if it does not already exist. It returns olric.ErrFound if the key already exist.
olric.IfFound: Only set the key if it already exist. It returns olric.ErrKeyNotFound if the key does not exist.
type PipelineResponse ¶ added in v0.2.0
type PipelineResponse struct { *Client // contains filtered or unexported fields }
PipelineResponse implements response readers for pipelined requests.
func (*PipelineResponse) Decr ¶ added in v0.2.0
func (pr *PipelineResponse) Decr() (int, error)
Decr atomically decrements key by delta. The return value is the new value after being decremented or an error.
func (*PipelineResponse) Delete ¶ added in v0.2.0
func (pr *PipelineResponse) Delete() error
Delete deletes the value for the given key. 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 (*PipelineResponse) Destroy ¶ added in v0.2.0
func (pr *PipelineResponse) Destroy() 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/PutEx calls may set new values to the dmap.
func (*PipelineResponse) Expire ¶ added in v0.2.0
func (pr *PipelineResponse) Expire() error
Expire updates the expiry for the given key. It returns ErrKeyNotFound if the DB does not contains the key. It's thread-safe.
func (*PipelineResponse) Get ¶ added in v0.2.0
func (pr *PipelineResponse) Get() (interface{}, error)
Get returns the value for the requested key. It returns ErrKeyNotFound if the DB does not contains the key. It's thread-safe. It is safe to modify the contents of the returned value. It is safe to modify the contents of the argument after Get returns.
func (*PipelineResponse) GetPut ¶ added in v0.2.0
func (pr *PipelineResponse) GetPut() (interface{}, error)
GetPut atomically sets key to value and returns the old value stored at key.
func (*PipelineResponse) Incr ¶ added in v0.2.0
func (pr *PipelineResponse) Incr() (int, error)
Incr atomically increments key by delta. The return value is the new value after being incremented or an error.
func (*PipelineResponse) Operation ¶ added in v0.2.0
func (pr *PipelineResponse) Operation() string
Operation returns the current operation name.
func (*PipelineResponse) Put ¶ added in v0.2.0
func (pr *PipelineResponse) Put() error
Put sets the value for the requested key. It overwrites any previous value for that key and it's thread-safe. It is safe to modify the contents of the arguments after Put returns but not before.
func (*PipelineResponse) PutEx ¶ added in v0.2.0
func (pr *PipelineResponse) PutEx() error
PutEx sets the value for the given key with TTL. It overwrites any previous value for that key. It's thread-safe. It is safe to modify the contents of the arguments after Put returns but not before.
func (*PipelineResponse) PutIf ¶ added in v0.2.0
func (pr *PipelineResponse) PutIf() error
func (*PipelineResponse) PutIfEx ¶ added in v0.2.0
func (pr *PipelineResponse) PutIfEx() error