commander

package
v0.0.0-...-917504b Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package commander is basically a connection to redis which supports multiple chained commands, and it can return the connection to the pool when finished It also handle scanning the results. commander supports multiple type safe redis commands

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commander

type Commander struct {
	// contains filtered or unexported fields
}

Commander provides a means to command redigo easily

func New

func New(conn redis.Conn) *Commander

New returns a new commander

func (*Commander) Command

func (c *Commander) Command(result interface{}, name string, args ...interface{}) *Commander

Command commands the redis connection

func (*Commander) Commit

func (c *Commander) Commit() error

Commit returns the results of all the commands

func (*Commander) Decr

func (c *Commander) Decr(result *int64, key string) *Commander

Decr decrements the number stored at key by one. If the key does not exist, it is set to 0.

func (*Commander) Del

func (c *Commander) Del(result *int, keys ...string) *Commander

Del removes the specified keys. A key is ignored if it does not exist.

func (*Commander) Exists

func (c *Commander) Exists(result *int, keys ...string) *Commander

Exists if key exists

func (*Commander) Expire

func (c *Commander) Expire(result *bool, key string, seconds int) *Commander

Expire set a timeout on key. After the timeout has expired, the key will automatically be deleted.

func (*Commander) FlushAll

func (c *Commander) FlushAll(result *string, options ...FlushAllOption) *Commander

FlushAll delete all the keys of all the existing databases, not just the currently selected one.

func (*Commander) Get

func (c *Commander) Get(result interface{}, key string) *Commander

Get the value of key. If the key does not exist the special value nil is returned.

func (*Commander) HGet

func (c *Commander) HGet(result interface{}, key, field string) *Commander

HGet Returns the value associated with field in the hash stored at key.

func (*Commander) HSet

func (c *Commander) HSet(result *int, key string, field []string, value []interface{}) *Commander

HSet sets field in the hash stored at key to value. If key does not exist, a new key holding a hash is created.

func (*Commander) Incr

func (c *Commander) Incr(result *int64, key string) *Commander

Incr Increments the number stored at key by one. If the key does not exist, it is set to 0.

func (*Commander) Keys

func (c *Commander) Keys(result *[]string, pattern string) *Commander

Keys returns all keys matching pattern.

func (*Commander) Ping

func (c *Commander) Ping(result *string, options ...PingOption) *Commander

Ping returns PONG if no argument is provided, otherwise return a copy of the argument as a bulk.

func (*Commander) Select

func (c *Commander) Select(result *string, index int) *Commander

Select the Redis logical database having the specified zero-based numeric index.

func (*Commander) Set

func (c *Commander) Set(result *string, key string, value interface{}, options ...SetOption) *Commander

Set key to hold the string value. If key already holds a value, it is overwritten.

Example (OptionSlice)

Example shows more complicated and dynamic use of options for example ex and nx variables are determined in run-time

package main

import (
	"fmt"

	"github.com/alibaba-go/bluto/bluto"
	"github.com/alibaba-go/bluto/commander"
)

var ex uint64 = 1
var nx bool = true

// Example shows more complicated and dynamic use of options
// for example ex and nx variables are determined in run-time
func main() {
	bluto, _ := bluto.New(bluto.Config{
		Address:               "localhost:6379",
		ConnectTimeoutSeconds: 10,
		ReadTimeoutSeconds:    10,
	})
	defer bluto.ClosePool()

	options := []commander.SetOption{}
	if nx != false {
		options = append(options, commander.SetOptionNX{})
	}
	if ex != 0 {
		options = append(options, commander.SetOptionEX{EX: ex})
	}

	var setResult string
	var getResult string

	bluto.Borrow().
		Set(&setResult, "SomeKey", "SomeValue", options...).
		Get(&getResult, "SomeKey").
		Commit()

	fmt.Println(getResult)

}
Output:

SomeValue

func (*Commander) XAck

func (c *Commander) XAck(result interface{}, streamName, groupName string, idList []string) *Commander

XAck removes one or multiple messages from the pending entries list (PEL) of a stream consumer group.

func (*Commander) XAdd

func (c *Commander) XAdd(result *string, streamName, streamID string, fields interface{}, options ...XAddOption) *Commander

XAdd appends the specified stream entry to the stream at the specified key.

func (*Commander) XClaim

func (c *Commander) XClaim(result interface{}, streamName, groupName, consumerName string, minIdleTime uint64, idList []string, options ...XClaimOption) *Commander

XClaim this command changes the ownership of a pending message, so that the new owner is the consumer specified as the command argument.

func (*Commander) XGroupCreate

func (c *Commander) XGroupCreate(result *string, streamName, groupName, streamID string, options ...XGroupCreateOption) *Commander

XGroupCreate is used in order to manage the consumer groups associated with a stream data structure.

func (*Commander) XGroupDelConsumer

func (c *Commander) XGroupDelConsumer(result *int, streamName, groupName, consumerName string) *Commander

XGroupDelConsumer is used in order to manage the consumer groups associated with a stream data structure.

func (*Commander) XGroupDestroy

func (c *Commander) XGroupDestroy(result *int, streamName, groupName string) *Commander

XGroupDestroy is used in order to manage the consumer groups associated with a stream data structure.

func (*Commander) XPending

func (c *Commander) XPending(result interface{}, streamName, groupName string, options ...XPendingOption) *Commander

XPending fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries.

func (*Commander) XRead

func (c *Commander) XRead(result interface{}, streamList, idList []string, options ...XReadOption) *Commander

XRead read data from one or multiple streams, only returning entries with an ID greater than the last received ID reported by the caller.

func (*Commander) XReadGroup

func (c *Commander) XReadGroup(result interface{}, groupName, consumerName string, streamList, idList []string, options ...XReadGroupOption) *Commander

XReadGroup s a special version of the XREAD command with support for consumer groups.

type FlushAllOption

type FlushAllOption interface {
	// contains filtered or unexported methods
}

FlushAllOption define option interface for redis FlushAll command.

type FlushAllOptionAsync

type FlushAllOptionAsync struct {
}

FlushAllOptionAsync let the entire dataset or a single database to be freed asynchronously.

type PingOption

type PingOption interface {
	// contains filtered or unexported methods
}

PingOption define option interface for redis Ping command.

type PingOptionMessage

type PingOptionMessage struct {
	Message string
}

PingOptionMessage returns a copy of the message.

type SetOption

type SetOption interface {
	// contains filtered or unexported methods
}

SetOption define option interface for redis Set command.

type SetOptionEX

type SetOptionEX struct {
	EX uint64
}

SetOptionEX (EX seconds) Set the specified expire time, in seconds.

type SetOptionKeepTTL

type SetOptionKeepTTL struct {
}

SetOptionKeepTTL (Redis>=6.0) Retain the time to live associated with the key.

type SetOptionNX

type SetOptionNX struct {
}

SetOptionNX Only set the key if it does not already exist.

type SetOptionPX

type SetOptionPX struct {
	PX uint64
}

SetOptionPX (PX milliseconds) Set the specified expire time, in milliseconds.

type SetOptionXX

type SetOptionXX struct {
}

SetOptionXX Only set the key if it already exist.

type XAddOption

type XAddOption interface {
	// contains filtered or unexported methods
}

XAddOption define option interface for redis XADD command.

type XAddOptionMaxLen

type XAddOptionMaxLen struct {
	MaxLen      uint64
	Approximate bool
}

XAddOptionMaxLen limit the size of the stream to a maximum number of elements.

type XClaimOption

type XClaimOption interface {
	// contains filtered or unexported methods
}

XClaimOption define option interface for redis XCLAIM command.

type XClaimOptionForce

type XClaimOptionForce struct {
}

XClaimOptionForce creates the pending message entry in the PEL even if certain specified IDs are not already in the PEL assigned to a different client.

type XClaimOptionIdle

type XClaimOptionIdle struct {
	Idle uint64
}

XClaimOptionIdle (Idle milliseconds) set the idle time (last time it was delivered) of the message.

type XClaimOptionJustID

type XClaimOptionJustID struct {
}

XClaimOptionJustID return just an array of IDs of messages successfully claimed, without returning the actual message.

type XClaimOptionRetryCount

type XClaimOptionRetryCount struct {
	RetryCount uint64
}

XClaimOptionRetryCount set the retry counter to the specified value.

type XClaimOptionTime

type XClaimOptionTime struct {
	Time uint64
}

XClaimOptionTime (Time milliseconds) is the same as IDLE but instead of a relative amount of milliseconds, it sets the idle time to a specific Unix time

type XGroupCreateOption

type XGroupCreateOption interface {
	// contains filtered or unexported methods
}

XGroupCreateOption define option interface for redis XGROUP CREATE command.

type XGroupCreateOptionMKStream

type XGroupCreateOptionMKStream struct {
}

XGroupCreateOptionMKStream creates stream if does not exists.

type XPendingOption

type XPendingOption interface {
	// contains filtered or unexported methods
}

XPendingOption define option interface for redis XPENDING command.

type XPendingOptionConsumer

type XPendingOptionConsumer struct {
	Consumer string
}

XPendingOptionConsumer summary about the pending messages in a given consumer group

type XPendingOptionStartEndCount

type XPendingOptionStartEndCount struct {
	StartID string
	EndID   string
	Count   uint64
}

XPendingOptionStartEndCount define pass a range of IDs, and a non optional count argument.

type XReadGroupOption

type XReadGroupOption interface {
	// contains filtered or unexported methods
}

XReadGroupOption define option interface for redis XREADGROUP command.

type XReadGroupOptionBlock

type XReadGroupOptionBlock struct {
	Block uint64
}

XReadGroupOptionBlock (Block milliseconds) set block duartion if items are not available.

type XReadGroupOptionCount

type XReadGroupOptionCount struct {
	Count uint64
}

XReadGroupOptionCount set maximum return count elements per stream.

type XReadGroupOptionNoAck

type XReadGroupOptionNoAck struct {
}

XReadGroupOptionNoAck avoid adding the message to the PEL.

type XReadOption

type XReadOption interface {
	// contains filtered or unexported methods
}

XReadOption define option interface for redis XREAD command.

type XReadOptionBlock

type XReadOptionBlock struct {
	Block uint64
}

XReadOptionBlock (Block milliseconds) set block duartion if items are not available.

type XReadOptionCount

type XReadOptionCount struct {
	Count uint64
}

XReadOptionCount set maximum return count elements per stream.

Jump to

Keyboard shortcuts

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