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 ¶
- type Commander
- func (c *Commander) Command(result interface{}, name string, args ...interface{}) *Commander
- func (c *Commander) Commit() error
- func (c *Commander) Decr(result *int64, key string) *Commander
- func (c *Commander) Del(result *int, keys ...string) *Commander
- func (c *Commander) Exists(result *int, keys ...string) *Commander
- func (c *Commander) Expire(result *bool, key string, seconds int) *Commander
- func (c *Commander) FlushAll(result *string, options ...FlushAllOption) *Commander
- func (c *Commander) Get(result interface{}, key string) *Commander
- func (c *Commander) HGet(result interface{}, key, field string) *Commander
- func (c *Commander) HSet(result *int, key string, field []string, value []interface{}) *Commander
- func (c *Commander) Incr(result *int64, key string) *Commander
- func (c *Commander) Keys(result *[]string, pattern string) *Commander
- func (c *Commander) Ping(result *string, options ...PingOption) *Commander
- func (c *Commander) Select(result *string, index int) *Commander
- func (c *Commander) Set(result *string, key string, value interface{}, options ...SetOption) *Commander
- func (c *Commander) XAck(result interface{}, streamName, groupName string, idList []string) *Commander
- func (c *Commander) XAdd(result *string, streamName, streamID string, fields interface{}, ...) *Commander
- func (c *Commander) XClaim(result interface{}, streamName, groupName, consumerName string, ...) *Commander
- func (c *Commander) XGroupCreate(result *string, streamName, groupName, streamID string, ...) *Commander
- func (c *Commander) XGroupDelConsumer(result *int, streamName, groupName, consumerName string) *Commander
- func (c *Commander) XGroupDestroy(result *int, streamName, groupName string) *Commander
- func (c *Commander) XPending(result interface{}, streamName, groupName string, options ...XPendingOption) *Commander
- func (c *Commander) XRead(result interface{}, streamList, idList []string, options ...XReadOption) *Commander
- func (c *Commander) XReadGroup(result interface{}, groupName, consumerName string, ...) *Commander
- type FlushAllOption
- type FlushAllOptionAsync
- type PingOption
- type PingOptionMessage
- type SetOption
- type SetOptionEX
- type SetOptionKeepTTL
- type SetOptionNX
- type SetOptionPX
- type SetOptionXX
- type XAddOption
- type XAddOptionMaxLen
- type XClaimOption
- type XClaimOptionForce
- type XClaimOptionIdle
- type XClaimOptionJustID
- type XClaimOptionRetryCount
- type XClaimOptionTime
- type XGroupCreateOption
- type XGroupCreateOptionMKStream
- type XPendingOption
- type XPendingOptionConsumer
- type XPendingOptionStartEndCount
- type XReadGroupOption
- type XReadGroupOptionBlock
- type XReadGroupOptionCount
- type XReadGroupOptionNoAck
- type XReadOption
- type XReadOptionBlock
- type XReadOptionCount
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 (*Commander) Decr ¶
Decr decrements the number stored at key by one. If the key does not exist, it is set to 0.
func (*Commander) Expire ¶
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 ¶
Get the value of key. If the key does not exist the special value nil is returned.
func (*Commander) HSet ¶
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 ¶
Incr Increments the number stored at key by one. If the key does not exist, it is set to 0.
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 ¶
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 ¶
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 XAddOption ¶
type XAddOption interface {
// contains filtered or unexported methods
}
XAddOption define option interface for redis XADD command.
type XAddOptionMaxLen ¶
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 ¶
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.