2013-09-29 12:06:49 +04:00
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
2015-05-28 15:51:19 +03:00
|
|
|
"bytes"
|
2013-09-29 12:06:49 +04:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2016-03-12 11:52:13 +03:00
|
|
|
|
2016-04-09 13:27:16 +03:00
|
|
|
"gopkg.in/redis.v4/internal/pool"
|
2013-09-29 12:06:49 +04:00
|
|
|
)
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
var (
|
|
|
|
_ Cmder = (*Cmd)(nil)
|
|
|
|
_ Cmder = (*SliceCmd)(nil)
|
|
|
|
_ Cmder = (*StatusCmd)(nil)
|
|
|
|
_ Cmder = (*IntCmd)(nil)
|
|
|
|
_ Cmder = (*DurationCmd)(nil)
|
|
|
|
_ Cmder = (*BoolCmd)(nil)
|
|
|
|
_ Cmder = (*StringCmd)(nil)
|
|
|
|
_ Cmder = (*FloatCmd)(nil)
|
|
|
|
_ Cmder = (*StringSliceCmd)(nil)
|
|
|
|
_ Cmder = (*BoolSliceCmd)(nil)
|
|
|
|
_ Cmder = (*StringStringMapCmd)(nil)
|
2015-01-25 15:05:19 +03:00
|
|
|
_ Cmder = (*StringIntMapCmd)(nil)
|
2014-07-05 14:46:27 +04:00
|
|
|
_ Cmder = (*ZSliceCmd)(nil)
|
2014-01-09 12:17:38 +04:00
|
|
|
_ Cmder = (*ScanCmd)(nil)
|
2016-04-09 12:52:43 +03:00
|
|
|
_ Cmder = (*ClusterSlotsCmd)(nil)
|
2014-01-09 12:17:38 +04:00
|
|
|
)
|
|
|
|
|
2013-09-29 12:06:49 +04:00
|
|
|
type Cmder interface {
|
2015-05-28 15:51:19 +03:00
|
|
|
args() []interface{}
|
2016-05-06 21:12:31 +03:00
|
|
|
arg(int) string
|
2016-03-12 11:52:13 +03:00
|
|
|
readReply(*pool.Conn) error
|
2013-09-29 12:06:49 +04:00
|
|
|
setErr(error)
|
2015-01-24 15:12:48 +03:00
|
|
|
reset()
|
2013-09-29 12:06:49 +04:00
|
|
|
|
|
|
|
readTimeout() *time.Duration
|
|
|
|
|
|
|
|
Err() error
|
2015-05-28 15:51:19 +03:00
|
|
|
fmt.Stringer
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2013-09-29 13:41:04 +04:00
|
|
|
func setCmdsErr(cmds []Cmder, e error) {
|
|
|
|
for _, cmd := range cmds {
|
|
|
|
cmd.setErr(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-10 15:33:04 +03:00
|
|
|
func resetCmds(cmds []Cmder) {
|
|
|
|
for _, cmd := range cmds {
|
|
|
|
cmd.reset()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func writeCmd(cn *pool.Conn, cmds ...Cmder) error {
|
|
|
|
cn.Buf = cn.Buf[:0]
|
|
|
|
for _, cmd := range cmds {
|
|
|
|
var err error
|
|
|
|
cn.Buf, err = appendArgs(cn.Buf, cmd.args())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := cn.Write(cn.Buf)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func cmdString(cmd Cmder, val interface{}) string {
|
2015-05-28 15:51:19 +03:00
|
|
|
var ss []string
|
|
|
|
for _, arg := range cmd.args() {
|
|
|
|
ss = append(ss, fmt.Sprint(arg))
|
|
|
|
}
|
|
|
|
s := strings.Join(ss, " ")
|
2014-01-09 12:17:38 +04:00
|
|
|
if err := cmd.Err(); err != nil {
|
|
|
|
return s + ": " + err.Error()
|
|
|
|
}
|
|
|
|
if val != nil {
|
2015-05-28 15:51:19 +03:00
|
|
|
switch vv := val.(type) {
|
|
|
|
case []byte:
|
|
|
|
return s + ": " + string(vv)
|
|
|
|
default:
|
|
|
|
return s + ": " + fmt.Sprint(val)
|
|
|
|
}
|
2014-01-09 12:17:38 +04:00
|
|
|
}
|
|
|
|
return s
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-29 12:06:49 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type baseCmd struct {
|
2015-05-28 15:51:19 +03:00
|
|
|
_args []interface{}
|
2016-05-06 21:12:31 +03:00
|
|
|
err error
|
2013-09-29 12:06:49 +04:00
|
|
|
|
2016-03-08 18:18:52 +03:00
|
|
|
_readTimeout *time.Duration
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *baseCmd) Err() error {
|
|
|
|
if cmd.err != nil {
|
|
|
|
return cmd.err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func (cmd *baseCmd) args() []interface{} {
|
2013-09-29 12:06:49 +04:00
|
|
|
return cmd._args
|
|
|
|
}
|
|
|
|
|
2016-05-06 21:12:31 +03:00
|
|
|
func (cmd *baseCmd) arg(pos int) string {
|
|
|
|
if len(cmd._args) > pos {
|
|
|
|
if s, ok := cmd._args[pos].(string); ok {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2013-09-29 12:06:49 +04:00
|
|
|
func (cmd *baseCmd) readTimeout() *time.Duration {
|
|
|
|
return cmd._readTimeout
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *baseCmd) setReadTimeout(d time.Duration) {
|
|
|
|
cmd._readTimeout = &d
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *baseCmd) setErr(e error) {
|
|
|
|
cmd.err = e
|
|
|
|
}
|
|
|
|
|
2016-05-06 21:12:31 +03:00
|
|
|
func newBaseCmd(args []interface{}) baseCmd {
|
|
|
|
return baseCmd{_args: args}
|
|
|
|
}
|
|
|
|
|
2013-09-29 12:06:49 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type Cmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
|
|
|
val interface{}
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewCmd(args ...interface{}) *Cmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
return &Cmd{baseCmd: newBaseCmd(args)}
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *Cmd) reset() {
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.val = nil
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2013-09-29 12:06:49 +04:00
|
|
|
func (cmd *Cmd) Val() interface{} {
|
|
|
|
return cmd.val
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *Cmd) Result() (interface{}, error) {
|
|
|
|
return cmd.val, cmd.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *Cmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *Cmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:09:20 +03:00
|
|
|
val, err := readReply(cn, sliceParser)
|
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return cmd.err
|
|
|
|
}
|
2016-04-12 19:41:56 +03:00
|
|
|
if b, ok := val.([]byte); ok {
|
|
|
|
// Bytes must be copied, because underlying memory is reused.
|
|
|
|
cmd.val = string(b)
|
|
|
|
} else {
|
|
|
|
cmd.val = val
|
|
|
|
}
|
2015-10-07 17:09:20 +03:00
|
|
|
return nil
|
2014-01-09 12:17:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type SliceCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
|
|
|
val []interface{}
|
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewSliceCmd(args ...interface{}) *SliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &SliceCmd{baseCmd: cmd}
|
2014-01-09 12:17:38 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *SliceCmd) reset() {
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.val = nil
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *SliceCmd) Val() []interface{} {
|
|
|
|
return cmd.val
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *SliceCmd) Result() ([]interface{}, error) {
|
|
|
|
return cmd.val, cmd.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *SliceCmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *SliceCmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:56:49 +03:00
|
|
|
v, err := readArrayReply(cn, sliceParser)
|
2014-01-09 12:17:38 +04:00
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cmd.val = v.([]interface{})
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-09-29 12:06:49 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type StatusCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
|
|
|
val string
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewStatusCmd(args ...interface{}) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &StatusCmd{baseCmd: cmd}
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *StatusCmd) reset() {
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.val = ""
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2013-09-29 12:06:49 +04:00
|
|
|
func (cmd *StatusCmd) Val() string {
|
2014-01-09 12:17:38 +04:00
|
|
|
return cmd.val
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *StatusCmd) Result() (string, error) {
|
|
|
|
return cmd.val, cmd.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *StatusCmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *StatusCmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:56:49 +03:00
|
|
|
cmd.val, cmd.err = readStringReply(cn)
|
|
|
|
return cmd.err
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type IntCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
|
|
|
val int64
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewIntCmd(args ...interface{}) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &IntCmd{baseCmd: cmd}
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *IntCmd) reset() {
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.val = 0
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2013-09-29 12:06:49 +04:00
|
|
|
func (cmd *IntCmd) Val() int64 {
|
2014-01-09 12:17:38 +04:00
|
|
|
return cmd.val
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *IntCmd) Result() (int64, error) {
|
|
|
|
return cmd.val, cmd.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *IntCmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *IntCmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:56:49 +03:00
|
|
|
cmd.val, cmd.err = readIntReply(cn)
|
|
|
|
return cmd.err
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2013-10-15 17:47:12 +04:00
|
|
|
type DurationCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
|
|
|
val time.Duration
|
2013-10-15 17:47:12 +04:00
|
|
|
precision time.Duration
|
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewDurationCmd(precision time.Duration, args ...interface{}) *DurationCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
2013-10-15 17:47:12 +04:00
|
|
|
return &DurationCmd{
|
|
|
|
precision: precision,
|
2016-05-06 21:12:31 +03:00
|
|
|
baseCmd: cmd,
|
2013-10-15 17:47:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *DurationCmd) reset() {
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.val = 0
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *DurationCmd) Val() time.Duration {
|
|
|
|
return cmd.val
|
2013-10-15 17:47:12 +04:00
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *DurationCmd) Result() (time.Duration, error) {
|
|
|
|
return cmd.val, cmd.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *DurationCmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *DurationCmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:56:49 +03:00
|
|
|
n, err := readIntReply(cn)
|
2014-01-09 12:17:38 +04:00
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return err
|
2013-10-15 17:47:12 +04:00
|
|
|
}
|
2015-10-07 17:56:49 +03:00
|
|
|
cmd.val = time.Duration(n) * cmd.precision
|
2014-01-09 12:17:38 +04:00
|
|
|
return nil
|
2013-10-15 17:47:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2013-09-29 12:06:49 +04:00
|
|
|
type BoolCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
|
|
|
val bool
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewBoolCmd(args ...interface{}) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &BoolCmd{baseCmd: cmd}
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *BoolCmd) reset() {
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.val = false
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *BoolCmd) Val() bool {
|
|
|
|
return cmd.val
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *BoolCmd) Result() (bool, error) {
|
|
|
|
return cmd.val, cmd.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *BoolCmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
var ok = []byte("OK")
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *BoolCmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:09:20 +03:00
|
|
|
v, err := readReply(cn, nil)
|
2015-10-07 17:56:49 +03:00
|
|
|
// `SET key value NX` returns nil when key already exists. But
|
|
|
|
// `SETNX key value` returns bool (0/1). So convert nil to bool.
|
2015-08-29 13:08:27 +03:00
|
|
|
// TODO: is this okay?
|
2015-01-31 12:08:56 +03:00
|
|
|
if err == Nil {
|
|
|
|
cmd.val = false
|
|
|
|
return nil
|
|
|
|
}
|
2014-01-09 12:17:38 +04:00
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return err
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
2015-01-31 12:08:56 +03:00
|
|
|
switch vv := v.(type) {
|
|
|
|
case int64:
|
|
|
|
cmd.val = vv == 1
|
|
|
|
return nil
|
2015-05-28 15:51:19 +03:00
|
|
|
case []byte:
|
|
|
|
cmd.val = bytes.Equal(vv, ok)
|
2015-01-31 12:08:56 +03:00
|
|
|
return nil
|
|
|
|
default:
|
2015-09-01 08:27:19 +03:00
|
|
|
return fmt.Errorf("got %T, wanted int64 or string", v)
|
2015-01-31 12:08:56 +03:00
|
|
|
}
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type StringCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
val []byte
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewStringCmd(args ...interface{}) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &StringCmd{baseCmd: cmd}
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *StringCmd) reset() {
|
2015-05-28 15:51:19 +03:00
|
|
|
cmd.val = nil
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2013-09-29 12:06:49 +04:00
|
|
|
func (cmd *StringCmd) Val() string {
|
2015-07-18 10:39:03 +03:00
|
|
|
return bytesToString(cmd.val)
|
2014-01-09 12:17:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *StringCmd) Result() (string, error) {
|
2015-05-28 15:51:19 +03:00
|
|
|
return cmd.Val(), cmd.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *StringCmd) Bytes() ([]byte, error) {
|
2014-01-09 12:17:38 +04:00
|
|
|
return cmd.val, cmd.err
|
|
|
|
}
|
|
|
|
|
2014-07-31 16:18:23 +04:00
|
|
|
func (cmd *StringCmd) Int64() (int64, error) {
|
|
|
|
if cmd.err != nil {
|
|
|
|
return 0, cmd.err
|
|
|
|
}
|
2015-05-28 15:51:19 +03:00
|
|
|
return strconv.ParseInt(cmd.Val(), 10, 64)
|
2014-07-31 16:18:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *StringCmd) Uint64() (uint64, error) {
|
|
|
|
if cmd.err != nil {
|
|
|
|
return 0, cmd.err
|
|
|
|
}
|
2015-05-28 15:51:19 +03:00
|
|
|
return strconv.ParseUint(cmd.Val(), 10, 64)
|
2014-07-31 16:18:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *StringCmd) Float64() (float64, error) {
|
|
|
|
if cmd.err != nil {
|
|
|
|
return 0, cmd.err
|
|
|
|
}
|
2015-05-28 15:51:19 +03:00
|
|
|
return strconv.ParseFloat(cmd.Val(), 64)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *StringCmd) Scan(val interface{}) error {
|
|
|
|
if cmd.err != nil {
|
|
|
|
return cmd.err
|
|
|
|
}
|
|
|
|
return scan(cmd.val, val)
|
2014-07-31 16:18:23 +04:00
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *StringCmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *StringCmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:56:49 +03:00
|
|
|
b, err := readBytesReply(cn)
|
2014-01-09 12:17:38 +04:00
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return err
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
2016-03-12 11:52:13 +03:00
|
|
|
|
|
|
|
new := make([]byte, len(b))
|
|
|
|
copy(new, b)
|
|
|
|
cmd.val = new
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
return nil
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type FloatCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
|
|
|
val float64
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewFloatCmd(args ...interface{}) *FloatCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &FloatCmd{baseCmd: cmd}
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *FloatCmd) reset() {
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.val = 0
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2013-09-29 12:06:49 +04:00
|
|
|
func (cmd *FloatCmd) Val() float64 {
|
2014-01-09 12:17:38 +04:00
|
|
|
return cmd.val
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-08-29 13:08:27 +03:00
|
|
|
func (cmd *FloatCmd) Result() (float64, error) {
|
|
|
|
return cmd.Val(), cmd.Err()
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *FloatCmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *FloatCmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:56:49 +03:00
|
|
|
cmd.val, cmd.err = readFloatReply(cn)
|
2014-01-09 12:17:38 +04:00
|
|
|
return cmd.err
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type StringSliceCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
|
|
|
val []string
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewStringSliceCmd(args ...interface{}) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &StringSliceCmd{baseCmd: cmd}
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *StringSliceCmd) reset() {
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.val = nil
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *StringSliceCmd) Val() []string {
|
|
|
|
return cmd.val
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2014-01-09 12:31:43 +04:00
|
|
|
func (cmd *StringSliceCmd) Result() ([]string, error) {
|
|
|
|
return cmd.Val(), cmd.Err()
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *StringSliceCmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *StringSliceCmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:56:49 +03:00
|
|
|
v, err := readArrayReply(cn, stringSliceParser)
|
2014-01-09 12:17:38 +04:00
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return err
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
2014-01-09 12:17:38 +04:00
|
|
|
cmd.val = v.([]string)
|
|
|
|
return nil
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type BoolSliceCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
|
|
|
val []bool
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewBoolSliceCmd(args ...interface{}) *BoolSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &BoolSliceCmd{baseCmd: cmd}
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *BoolSliceCmd) reset() {
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.val = nil
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *BoolSliceCmd) Val() []bool {
|
|
|
|
return cmd.val
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *BoolSliceCmd) Result() ([]bool, error) {
|
|
|
|
return cmd.val, cmd.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *BoolSliceCmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *BoolSliceCmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:56:49 +03:00
|
|
|
v, err := readArrayReply(cn, boolSliceParser)
|
2014-01-09 12:17:38 +04:00
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return err
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
2014-01-09 12:17:38 +04:00
|
|
|
cmd.val = v.([]bool)
|
|
|
|
return nil
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type StringStringMapCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
|
|
|
val map[string]string
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewStringStringMapCmd(args ...interface{}) *StringStringMapCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &StringStringMapCmd{baseCmd: cmd}
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *StringStringMapCmd) reset() {
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.val = nil
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *StringStringMapCmd) Val() map[string]string {
|
|
|
|
return cmd.val
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
func (cmd *StringStringMapCmd) Result() (map[string]string, error) {
|
|
|
|
return cmd.val, cmd.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *StringStringMapCmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *StringStringMapCmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:56:49 +03:00
|
|
|
v, err := readArrayReply(cn, stringStringMapParser)
|
2014-01-09 12:17:38 +04:00
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return err
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
2014-01-09 12:17:38 +04:00
|
|
|
cmd.val = v.(map[string]string)
|
|
|
|
return nil
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-01-25 15:05:19 +03:00
|
|
|
type StringIntMapCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2015-01-25 15:05:19 +03:00
|
|
|
|
|
|
|
val map[string]int64
|
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewStringIntMapCmd(args ...interface{}) *StringIntMapCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &StringIntMapCmd{baseCmd: cmd}
|
2015-01-25 15:05:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *StringIntMapCmd) Val() map[string]int64 {
|
|
|
|
return cmd.val
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *StringIntMapCmd) Result() (map[string]int64, error) {
|
|
|
|
return cmd.val, cmd.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *StringIntMapCmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *StringIntMapCmd) reset() {
|
|
|
|
cmd.val = nil
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *StringIntMapCmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:56:49 +03:00
|
|
|
v, err := readArrayReply(cn, stringIntMapParser)
|
2015-01-25 15:05:19 +03:00
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cmd.val = v.(map[string]int64)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2014-07-05 14:46:27 +04:00
|
|
|
type ZSliceCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
2014-07-05 14:46:27 +04:00
|
|
|
val []Z
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewZSliceCmd(args ...interface{}) *ZSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &ZSliceCmd{baseCmd: cmd}
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *ZSliceCmd) reset() {
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.val = nil
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2014-07-05 14:46:27 +04:00
|
|
|
func (cmd *ZSliceCmd) Val() []Z {
|
2014-01-09 12:17:38 +04:00
|
|
|
return cmd.val
|
|
|
|
}
|
|
|
|
|
2014-07-05 14:46:27 +04:00
|
|
|
func (cmd *ZSliceCmd) Result() ([]Z, error) {
|
2014-01-09 12:17:38 +04:00
|
|
|
return cmd.val, cmd.err
|
|
|
|
}
|
|
|
|
|
2014-07-05 14:46:27 +04:00
|
|
|
func (cmd *ZSliceCmd) String() string {
|
2014-01-09 12:17:38 +04:00
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *ZSliceCmd) readReply(cn *pool.Conn) error {
|
2015-10-07 17:56:49 +03:00
|
|
|
v, err := readArrayReply(cn, zSliceParser)
|
2014-01-09 12:17:38 +04:00
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return err
|
|
|
|
}
|
2014-07-05 14:46:27 +04:00
|
|
|
cmd.val = v.([]Z)
|
2014-01-09 12:17:38 +04:00
|
|
|
return nil
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:38 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type ScanCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
2014-01-09 12:17:38 +04:00
|
|
|
|
2016-04-13 11:52:47 +03:00
|
|
|
page []string
|
2016-04-09 13:07:42 +03:00
|
|
|
cursor uint64
|
2014-01-09 12:17:38 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func NewScanCmd(args ...interface{}) *ScanCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
2016-04-13 11:52:47 +03:00
|
|
|
return &ScanCmd{
|
2016-05-06 21:12:31 +03:00
|
|
|
baseCmd: cmd,
|
2016-04-13 11:52:47 +03:00
|
|
|
}
|
2014-01-09 12:17:38 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (cmd *ScanCmd) reset() {
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.cursor = 0
|
2016-04-13 11:52:47 +03:00
|
|
|
cmd.page = nil
|
2015-01-13 13:33:45 +03:00
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2016-04-09 13:07:42 +03:00
|
|
|
func (cmd *ScanCmd) Val() (keys []string, cursor uint64) {
|
|
|
|
return cmd.page, cmd.cursor
|
2014-01-09 12:17:38 +04:00
|
|
|
}
|
|
|
|
|
2016-04-09 13:07:42 +03:00
|
|
|
func (cmd *ScanCmd) Result() (keys []string, cursor uint64, err error) {
|
|
|
|
return cmd.page, cmd.cursor, cmd.err
|
2014-01-09 12:17:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *ScanCmd) String() string {
|
2016-04-13 11:52:47 +03:00
|
|
|
return cmdString(cmd, cmd.page)
|
2014-01-09 12:17:38 +04:00
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *ScanCmd) readReply(cn *pool.Conn) error {
|
2016-04-13 11:52:47 +03:00
|
|
|
page, cursor, err := readScanReply(cn)
|
2014-01-09 12:17:38 +04:00
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return cmd.err
|
|
|
|
}
|
2016-04-13 11:52:47 +03:00
|
|
|
cmd.page = page
|
2015-10-07 17:56:49 +03:00
|
|
|
cmd.cursor = cursor
|
2014-01-09 12:17:38 +04:00
|
|
|
return nil
|
2013-09-29 12:06:49 +04:00
|
|
|
}
|
2015-01-24 15:12:48 +03:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-04-09 12:52:43 +03:00
|
|
|
type ClusterNode struct {
|
|
|
|
Id string
|
|
|
|
Addr string
|
|
|
|
}
|
|
|
|
|
|
|
|
type ClusterSlot struct {
|
2015-10-07 17:09:20 +03:00
|
|
|
Start int
|
|
|
|
End int
|
2016-04-09 12:52:43 +03:00
|
|
|
Nodes []ClusterNode
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
|
|
|
|
2016-04-09 12:52:43 +03:00
|
|
|
type ClusterSlotsCmd struct {
|
2015-01-24 15:12:48 +03:00
|
|
|
baseCmd
|
|
|
|
|
2016-04-09 12:52:43 +03:00
|
|
|
val []ClusterSlot
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
|
|
|
|
2016-04-09 12:52:43 +03:00
|
|
|
func NewClusterSlotsCmd(args ...interface{}) *ClusterSlotsCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &ClusterSlotsCmd{baseCmd: cmd}
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
|
|
|
|
2016-04-09 12:52:43 +03:00
|
|
|
func (cmd *ClusterSlotsCmd) Val() []ClusterSlot {
|
2015-01-24 15:12:48 +03:00
|
|
|
return cmd.val
|
|
|
|
}
|
|
|
|
|
2016-04-09 12:52:43 +03:00
|
|
|
func (cmd *ClusterSlotsCmd) Result() ([]ClusterSlot, error) {
|
2015-01-24 15:12:48 +03:00
|
|
|
return cmd.Val(), cmd.Err()
|
|
|
|
}
|
|
|
|
|
2016-04-09 12:52:43 +03:00
|
|
|
func (cmd *ClusterSlotsCmd) String() string {
|
2015-01-24 15:12:48 +03:00
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
2016-04-09 12:52:43 +03:00
|
|
|
func (cmd *ClusterSlotsCmd) reset() {
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd.val = nil
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2016-04-09 12:52:43 +03:00
|
|
|
func (cmd *ClusterSlotsCmd) readReply(cn *pool.Conn) error {
|
|
|
|
v, err := readArrayReply(cn, clusterSlotsParser)
|
2015-01-24 15:12:48 +03:00
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return err
|
|
|
|
}
|
2016-04-09 12:52:43 +03:00
|
|
|
cmd.val = v.([]ClusterSlot)
|
2015-01-24 15:12:48 +03:00
|
|
|
return nil
|
|
|
|
}
|
2015-09-20 16:13:13 +03:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-10-07 17:09:20 +03:00
|
|
|
// GeoLocation is used with GeoAdd to add geospatial location.
|
2015-09-20 16:13:13 +03:00
|
|
|
type GeoLocation struct {
|
2015-11-14 17:36:21 +03:00
|
|
|
Name string
|
|
|
|
Longitude, Latitude, Dist float64
|
|
|
|
GeoHash int64
|
2015-09-20 16:13:13 +03:00
|
|
|
}
|
|
|
|
|
2015-10-07 17:09:20 +03:00
|
|
|
// GeoRadiusQuery is used with GeoRadius to query geospatial index.
|
|
|
|
type GeoRadiusQuery struct {
|
2015-10-15 00:39:39 +03:00
|
|
|
Radius float64
|
2015-10-07 17:09:20 +03:00
|
|
|
// Can be m, km, ft, or mi. Default is km.
|
2015-10-15 00:39:39 +03:00
|
|
|
Unit string
|
|
|
|
WithCoord bool
|
|
|
|
WithDist bool
|
|
|
|
WithGeoHash bool
|
|
|
|
Count int
|
2015-10-07 17:09:20 +03:00
|
|
|
// Can be ASC or DESC. Default is no sort order.
|
|
|
|
Sort string
|
|
|
|
}
|
|
|
|
|
|
|
|
type GeoLocationCmd struct {
|
2015-09-20 16:13:13 +03:00
|
|
|
baseCmd
|
|
|
|
|
2015-11-14 17:36:21 +03:00
|
|
|
q *GeoRadiusQuery
|
2015-09-20 16:13:13 +03:00
|
|
|
locations []GeoLocation
|
|
|
|
}
|
|
|
|
|
2015-11-14 17:36:21 +03:00
|
|
|
func NewGeoLocationCmd(q *GeoRadiusQuery, args ...interface{}) *GeoLocationCmd {
|
|
|
|
args = append(args, q.Radius)
|
|
|
|
if q.Unit != "" {
|
|
|
|
args = append(args, q.Unit)
|
|
|
|
} else {
|
|
|
|
args = append(args, "km")
|
|
|
|
}
|
|
|
|
if q.WithCoord {
|
|
|
|
args = append(args, "WITHCOORD")
|
|
|
|
}
|
|
|
|
if q.WithDist {
|
|
|
|
args = append(args, "WITHDIST")
|
|
|
|
}
|
|
|
|
if q.WithGeoHash {
|
|
|
|
args = append(args, "WITHHASH")
|
|
|
|
}
|
|
|
|
if q.Count > 0 {
|
|
|
|
args = append(args, "COUNT", q.Count)
|
|
|
|
}
|
|
|
|
if q.Sort != "" {
|
|
|
|
args = append(args, q.Sort)
|
|
|
|
}
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := newBaseCmd(args)
|
2015-11-14 17:36:21 +03:00
|
|
|
return &GeoLocationCmd{
|
2016-05-06 21:12:31 +03:00
|
|
|
baseCmd: cmd,
|
|
|
|
q: q,
|
2015-11-14 17:36:21 +03:00
|
|
|
}
|
2015-09-20 16:13:13 +03:00
|
|
|
}
|
|
|
|
|
2015-10-07 17:09:20 +03:00
|
|
|
func (cmd *GeoLocationCmd) reset() {
|
2015-09-20 16:13:13 +03:00
|
|
|
cmd.locations = nil
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
2015-10-07 17:09:20 +03:00
|
|
|
func (cmd *GeoLocationCmd) Val() []GeoLocation {
|
2015-09-20 16:13:13 +03:00
|
|
|
return cmd.locations
|
|
|
|
}
|
|
|
|
|
2015-10-07 17:09:20 +03:00
|
|
|
func (cmd *GeoLocationCmd) Result() ([]GeoLocation, error) {
|
2015-09-20 16:13:13 +03:00
|
|
|
return cmd.locations, cmd.err
|
|
|
|
}
|
|
|
|
|
2015-10-07 17:09:20 +03:00
|
|
|
func (cmd *GeoLocationCmd) String() string {
|
2015-09-20 16:13:13 +03:00
|
|
|
return cmdString(cmd, cmd.locations)
|
|
|
|
}
|
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
func (cmd *GeoLocationCmd) readReply(cn *pool.Conn) error {
|
2015-11-14 17:36:21 +03:00
|
|
|
reply, err := readArrayReply(cn, newGeoLocationSliceParser(cmd.q))
|
2015-09-20 16:13:13 +03:00
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
2015-10-07 17:09:20 +03:00
|
|
|
return err
|
2015-09-20 16:13:13 +03:00
|
|
|
}
|
2015-10-07 17:09:20 +03:00
|
|
|
cmd.locations = reply.([]GeoLocation)
|
2015-09-20 16:13:13 +03:00
|
|
|
return nil
|
|
|
|
}
|
2016-05-06 21:12:31 +03:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type CommandInfo struct {
|
|
|
|
Name string
|
|
|
|
Arity int8
|
|
|
|
Flags []string
|
|
|
|
FirstKeyPos int8
|
|
|
|
LastKeyPos int8
|
|
|
|
StepCount int8
|
|
|
|
ReadOnly bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type CommandsInfoCmd struct {
|
|
|
|
baseCmd
|
|
|
|
|
|
|
|
val map[string]*CommandInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCommandsInfoCmd(args ...interface{}) *CommandsInfoCmd {
|
|
|
|
cmd := newBaseCmd(args)
|
|
|
|
return &CommandsInfoCmd{baseCmd: cmd}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *CommandsInfoCmd) Val() map[string]*CommandInfo {
|
|
|
|
return cmd.val
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *CommandsInfoCmd) Result() (map[string]*CommandInfo, error) {
|
|
|
|
return cmd.Val(), cmd.Err()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *CommandsInfoCmd) String() string {
|
|
|
|
return cmdString(cmd, cmd.val)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *CommandsInfoCmd) reset() {
|
|
|
|
cmd.val = nil
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *CommandsInfoCmd) readReply(cn *pool.Conn) error {
|
|
|
|
v, err := readArrayReply(cn, commandInfoSliceParser)
|
|
|
|
if err != nil {
|
|
|
|
cmd.err = err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cmd.val = v.(map[string]*CommandInfo)
|
|
|
|
return nil
|
|
|
|
}
|