client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package client implements a Golang client to access an OlricDB cluster from outside.

Index

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 represents a Golang client to access an OlricDB cluster from outside.

func New

func New(servers []string, c *http.Client) (*Client, error)

New returns a new Client object. The second parameter is http.Client. It can be nil. Server names have to be start with protocol scheme: http or https.

func (*Client) Close

func (c *Client) Close()

Close cancels underlying context and cancels ongoing requests.

func (*Client) Delete

func (c *Client) Delete(name, key string) 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 (*Client) Destroy

func (c *Client) Destroy(name string) 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 (*Client) Get

func (c *Client) Get(name, key string) (interface{}, error)

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 (*Client) LockWithTimeout

func (c *Client) LockWithTimeout(name, key string, timeout time.Duration) 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 map. Please note that, before setting a lock for a key, you should set the key with Put method. Otherwise it returns olricdb.ErrKeyNotFound error.

It returns immediately if it acquires the lock for the given key. Otherwise, it waits until timeout. The timeout is determined by http.Client which can be configured via Config structure.

You should know that the locks are approximate, and only to be used for non-critical purposes.

func (*Client) Put

func (c *Client) Put(name, key string, value interface{}) error

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 (*Client) PutEx

func (c *Client) PutEx(name, key string, value interface{}, timeout time.Duration) 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 (*Client) Unlock

func (c *Client) Unlock(name, key string) error

Unlock releases an acquired lock for the given key. It returns olricdb.ErrNoSuchLock if there is no lock for the given key.

Jump to

Keyboard shortcuts

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