client

package
v0.3.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

README

Golang Client

This package provides a Golang client for Olric Binary Protocol. The client is straightforward to use and it's identical with the client in embedded member mode.

This implementation also supports connection pooling by default.

Table of Contents

Setup

The client package has a simple Config structure.

import "github.com/buraksezer/olric/client"
...
...
var clientConfig = &client.Config{
    Addrs:       []string{"localhost:3320"},
    Serializer:  serializer.NewMsgpackSerializer(),
    DialTimeout: 10 * time.Second,
    KeepAlive:   10 * time.Second,
    MaxConn:     100,
}

Now, we can create a new Client instance:

c, err := client.New(clientConfig)

A client (it's c in our sample) instance should be created one time in your program's life time. See Sample Code section to see it in action.

Data Structures

Olric currently provides two different data structures:

Distributed Map

Before starting, you need to create a new DMap instance:

dm := c.NewDMap("mydmap")

The methods under DMap struct is thread-safe. If you have an alive client instance, creating a DMap instance is not a costly operation. However, you still should be created only one DMap instance, if it's possible. There is no need to close DMap instances after use.

Put

Put sets the value for the given key. It overwrites any previous value for that key and it's thread-safe.

err := dm.Put("my-key", "my-value")

The key has to be string. Value type is arbitrary. It is safe to modify the contents of the arguments after Put returns but not before.

PutIf

PutIf sets the value for the given key. It overwrites any previous value for that key and it's thread-safe.

err := dm.PutIf("my-key", "my-value", flags)

The key has to be string. Value type is arbitrary. 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.

Sample use:

err := dm.PutIfEx("my-key", "my-value", time.Second, IfNotFound)
PutEx

PutEx sets the value for the given key with TTL. It overwrites any previous value for that key. It's thread-safe.

err := dm.PutEx("my-key", "my-value", time.Second)

The key has to be string. Value type is arbitrary. It is safe to modify the contents of the arguments after PutEx returns but not before.

PutIfEx

PutIfEx sets the value for the given key with TTL. It overwrites any previous value for that key. It's thread-safe.

err := dm.PutIfEx("my-key", "my-value", time.Second, flags)

The key has to be string. Value type is arbitrary. It is safe to modify the contents of the arguments after PutEx 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.

Sample use:

err := dm.PutIfEx("my-key", "my-value", time.Second, IfNotFound)
Get

Get gets the value for the given key. It returns olric.ErrKeyNotFound if the DB does not contains the key. It's thread-safe.

value, err := dm.Get("my-key")

It is safe to modify the contents of the returned value. It is safe to modify the contents of the argument after Get returns.

Expire

Expire updates the expiry for the given key. It returns olric.ErrKeyNotFound if the DB does not contains the key. It's thread-safe.

err := dm.Expire("my-key", time.Second)

The key has to be string. The second parameter is time.Duration.

Delete

Delete deletes the value for the given key. Delete will not return error if key doesn't exist. It's thread-safe.

err := dm.Delete("my-key")

It is safe to modify the contents of the argument after Delete returns.

LockWithTimeout

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.

ctx, err := dm.LockWithTimeout("lock.foo", time.Millisecond, time.Second)

It returns immediately if it acquires the lock for the given key. Otherwise, it waits until deadline. You should keep LockContext (as ctx) value to call Unlock method to release the lock.

Creating a seperated DMap to keep locks may be a good idea.

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

Please take a look at Lock Implementation section for implementation details.

Lock

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.

ctx, err := dm.Lock("lock.foo", time.Second)

It returns immediately if it acquires the lock for the given key. Otherwise, it waits until deadline. You should keep LockContext (as ctx) value to call Unlock method to release the lock.

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

Unlock

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

err := ctx.Unlock()
Destroy

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.

err := dm.Destroy()
Stats

Stats exposes some useful metrics to monitor an Olric node. It includes memory allocation metrics from partitions and the Go runtime metrics.

data, err := c.Stats()

See olric/stats/stats.go for detailed info about the metrics.

Ping

Ping sends a dummy protocol messsage to the given host. This is useful to measure RTT between hosts. It also can be used as aliveness check.

err := c.Ping()
Query

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": "",
	  },
  }

This is how you call a distributed query over the cluster:

c, err := dm.Query(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.

Cursor

Cursor implements distributed queries in Olric. It has two methods: Range and Close

Range

Range calls f sequentially for each key and value yielded from the cursor. If f returns false, range stops the iteration.

err := c.Range(func(key string, value interface{}) bool {
		fmt.Printf("KEY: %s, VALUE: %v\n", key, value)
		return true
})
Close

Close cancels the underlying context and background goroutines stops running. It's a good idea that defer Close after getting a Cursor. By this way, you can ensure that there is no dangling goroutine after your distributed query execution is stopped.

c.Close()

Atomic Operations

Normally, write operations in Olric is performed by the partition owners. However, atomic operations are guarded by a fine-grained lock implementation which can be found under internal/locker.

You should know that Olric is an AP product. So Olric may return inconsistent results in the case of network partitioning.

internal/locker is provided by the Docker.

Incr

Incr atomically increments key by delta. The return value is the new value after being incremented or an error.

nr, err := dm.Incr("atomic-key", 3)

The returned value is int.

Decr

Decr atomically decrements key by delta. The return value is the new value after being decremented or an error.

nr, err := dm.Decr("atomic-key", 1)

The returned value is int.

GetPut

GetPut atomically sets key to value and returns the old value stored at key.

value, err := dm.GetPut("atomic-key", someType{})

The returned value is an arbitrary type.

Distributed Topic

Distributed topic is an asynchronous messaging service that decouples services that produce events from services that process events. It has two delivery modes:

  • olric.UnorderedDelivery: Messages are delivered in random order. It's good to distribute independent events in a distributed system.
  • olric.OrderedDelivery: Messages are delivered in some order. Not implemented yet.

You should know that:

  • Communication between parties is one-to-many (fan-out).
  • All data is in-memory, and the published messages are not stored in the cluster.
  • Fire&Forget: message delivery is not guaranteed.

Create a DTopic instance:

dt, err := db.NewDTopic("my-topic", 0, olric.UnorderedDelivery)
Publish

Publish sends a message to the given topic. It accepts any serializable type as message.

err := dt.Publish("my-message")
AddListener

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.

listenerID, err := dt.AddListener(func(msg DTopicMessage) {
    fmt.Println("Message:", msg)
})

You have to store listenerID to remove the listener.

RemoveListener

RemoveListener removes a listener with the given listenerID.

err := dt.RemoveListener(listenerID)
Destroy

Destroy a DTopic from the cluster. It stops background goroutines and releases underlying data structures.

err := dt.Destroy()

Serialization

All data in an Olric cluster has to be serialized into byte form before transferring or storing. You can freely choice the serialization format for your data. Msgpack, Gob and JSON formats are supported by default. Any serialization format can be adapted by implementing the following interface:

// Serializer interface responsible for encoding/decoding values to transmit over network between Olric nodes.
type Serializer interface {
	// Marshal encodes v and returns a byte slice and possible error.
	Marshal(v interface{}) ([]byte, error)

	// Unmarshal decodes the encoded data and stores the result in the value pointed to by v.
	Unmarshal(data []byte, v interface{}) error
}

The default serializer is Gob serializer. The Msgpack serializer is the fastest one. While creating a new client configuration:

...
Serializer: serializer.NewMsgpackSerializer()
...

Available ones:

  • serializer.NewMsgpackSerializer()
  • serializer.NewJSONSerializer()
  • serializer.NewGobSerializer()

Sample Code

Here is a simple example for quick experimenting. Please note that you need to run an olricd instance at TCP port 3320 to run this sample.

package main

import (
	"fmt"
	"log"
	"strconv"

	"github.com/buraksezer/olric/client"
	"github.com/buraksezer/olric/serializer"
)

func main() {
	cc := &client.Config{
		Addrs:      []string{"127.0.0.1:3320"},
		MaxConn:    10,
		Serializer: serializer.NewMsgpackSerializer(),
	}

	// Create a new client instance
	c, err := client.New(cc)
	if err != nil {
		log.Fatalf("Olric client returned error: %s", err)
	}
	defer c.Close()

	// Create a DMap instance
	dm := c.NewDMap("my-dmap")
	for i := 0; i < 10; i++ {
		key := strconv.Itoa(i)
		value := strconv.Itoa(i * 2)
		if err = dm.Put(key, value); err != nil {
			log.Fatalf("put failed for %s: %s", key, err)
		}
		fmt.Printf("[PUT] Key: %s, Value: %s\n", key, value)
	}

	fmt.Printf("\n")

	for i := 0; i < 10; i++ {
		key := strconv.Itoa(i)
		value, err := dm.Get(key)
		if err != nil {
			log.Fatalf("get failed for %s: %s", err)
		}
		fmt.Printf("[GET] Key: %s, Value: %s\n", key, value)
	}
}

Documentation

Overview

Package client implements a Golang client to access an Olric 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 implements Go client of Olric Binary Protocol and its methods.

func New

func New(c *Config) (*Client, error)

New returns a new Client instance. The second parameter is serializer, it can be nil.

func (*Client) Close

func (c *Client) Close()

Close cancels underlying context and cancels ongoing requests.

func (*Client) NewDMap added in v0.2.0

func (c *Client) NewDMap(name string) *DMap

NewDMap creates and returns a new dmap instance to access DMaps on the cluster.

func (*Client) NewDTopic added in v0.3.0

func (c *Client) NewDTopic(name string, concurrency int, flag int16) (*DTopic, error)

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

func (c *Client) NewPipeline() *Pipeline

NewPipeline returns a new Pipeline.

func (*Client) Ping added in v0.2.0

func (c *Client) Ping(addr string) error

Ping sends a dummy protocol messsage to the given host. This is useful to measure RTT between hosts. It also can be used as aliveness check.

func (*Client) Stats added in v0.2.0

func (c *Client) Stats(addr string) (stats.Stats, error)

Stats exposes some useful metrics to monitor an Olric node.

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.

func (*Cursor) Close added in v0.2.0

func (c *Cursor) Close()

Close cancels the underlying context and stops background goroutines.

func (*Cursor) Range added in v0.2.0

func (c *Cursor) Range(f func(key string, value interface{}) bool) error

Range calls f sequentially for each key and value yielded from the cursor. If f returns false, range stops the iteration.

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

func (d *DMap) Decr(key string, delta int) (int, error)

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

func (d *DMap) Delete(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 (*DMap) Destroy added in v0.2.0

func (d *DMap) 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/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

func (d *DMap) Expire(key string, timeout time.Duration) 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 (*DMap) Get added in v0.2.0

func (d *DMap) Get(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 (*DMap) GetPut added in v0.2.0

func (d *DMap) GetPut(key string, value interface{}) (interface{}, error)

GetPut atomically sets key to value and returns the old value stored at key.

func (*DMap) Incr added in v0.2.0

func (d *DMap) Incr(key string, delta int) (int, error)

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

func (d *DMap) Lock(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 (*DMap) LockWithTimeout added in v0.2.0

func (d *DMap) LockWithTimeout(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 (*DMap) Put added in v0.2.0

func (d *DMap) Put(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 (*DMap) PutEx added in v0.2.0

func (d *DMap) PutEx(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 (*DMap) PutIf added in v0.2.0

func (d *DMap) PutIf(key string, value interface{}, flags int16) error

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

func (d *DMap) PutIfEx(key string, value interface{}, timeout time.Duration, flags int16) error

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

func (d *DMap) Query(q query.M) (*Cursor, error)

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

func (dt *DTopic) Destroy() error

Destroy a DTopic from the cluster. It stops background goroutines and releases underlying data structures.

func (*DTopic) Publish added in v0.3.0

func (dt *DTopic) Publish(msg interface{}) error

Publish sends a message to the given topic. It accepts any serializable type as message.

func (*DTopic) RemoveListener added in v0.3.0

func (dt *DTopic) RemoveListener(listenerID uint64) error

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

func (p *Pipeline) Decr(dmap, key string, delta int) error

Decr appends a Decr command to the underlying buffer with the given parameters.

func (*Pipeline) Delete added in v0.2.0

func (p *Pipeline) Delete(dmap, key string) error

Delete appends a Delete command to the underlying buffer with the given parameters.

func (*Pipeline) Destroy added in v0.2.0

func (p *Pipeline) Destroy(dmap string) error

Destroy appends a Destroy command to the underlying buffer with the given parameters.

func (*Pipeline) Expire added in v0.2.0

func (p *Pipeline) Expire(dmap, key string, timeout time.Duration) 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 (*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

func (p *Pipeline) Get(dmap, key string) error

Get appends a Get command to the underlying buffer with the given parameters.

func (*Pipeline) GetPut added in v0.2.0

func (p *Pipeline) GetPut(dmap, key string, value interface{}) error

GetPut appends a GetPut command to the underlying buffer with the given parameters.

func (*Pipeline) Incr added in v0.2.0

func (p *Pipeline) Incr(dmap, key string, delta int) error

Incr appends an Incr command to the underlying buffer with the given parameters.

func (*Pipeline) Put added in v0.2.0

func (p *Pipeline) Put(dmap, key string, value interface{}) error

Put appends a Put command to the underlying buffer with the given parameters.

func (*Pipeline) PutEx added in v0.2.0

func (p *Pipeline) PutEx(dmap, key string, value interface{}, timeout time.Duration) error

PutEx appends a PutEx command to the underlying buffer with the given parameters.

func (*Pipeline) PutIf added in v0.2.0

func (p *Pipeline) PutIf(dmap, key string, value interface{}, flags int16) error

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

Jump to

Keyboard shortcuts

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