1 Star 0 Fork 0

Survivor_zzc/redis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
commands.go 39.44 KB
一键复制 编辑 原始数据 按行查看 历史
Vladimir Mihailenco 提交于 2015-11-14 16:36 . Fix GeoRadius reply parsing.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
package redis
import (
"io"
"log"
"strconv"
"time"
)
func formatInt(i int64) string {
return strconv.FormatInt(i, 10)
}
func formatUint(i uint64) string {
return strconv.FormatUint(i, 10)
}
func formatFloat(f float64) string {
return strconv.FormatFloat(f, 'f', -1, 64)
}
func readTimeout(timeout time.Duration) time.Duration {
if timeout == 0 {
return 0
}
return timeout + time.Second
}
func usePrecise(dur time.Duration) bool {
return dur < time.Second || dur%time.Second != 0
}
func formatMs(dur time.Duration) string {
if dur > 0 && dur < time.Millisecond {
log.Printf(
"redis: specified duration is %s, but minimal supported value is %s",
dur, time.Millisecond,
)
}
return formatInt(int64(dur / time.Millisecond))
}
func formatSec(dur time.Duration) string {
if dur > 0 && dur < time.Second {
log.Printf(
"redis: specified duration is %s, but minimal supported value is %s",
dur, time.Second,
)
}
return formatInt(int64(dur / time.Second))
}
type commandable struct {
process func(cmd Cmder)
}
func (c *commandable) Process(cmd Cmder) {
c.process(cmd)
}
//------------------------------------------------------------------------------
func (c *commandable) Auth(password string) *StatusCmd {
cmd := newKeylessStatusCmd("AUTH", password)
c.Process(cmd)
return cmd
}
func (c *commandable) Echo(message string) *StringCmd {
cmd := NewStringCmd("ECHO", message)
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) Ping() *StatusCmd {
cmd := newKeylessStatusCmd("PING")
c.Process(cmd)
return cmd
}
func (c *commandable) Quit() *StatusCmd {
panic("not implemented")
}
func (c *commandable) Select(index int64) *StatusCmd {
cmd := newKeylessStatusCmd("SELECT", index)
c.Process(cmd)
return cmd
}
//------------------------------------------------------------------------------
func (c *commandable) Del(keys ...string) *IntCmd {
args := make([]interface{}, 1+len(keys))
args[0] = "DEL"
for i, key := range keys {
args[1+i] = key
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) Dump(key string) *StringCmd {
cmd := NewStringCmd("DUMP", key)
c.Process(cmd)
return cmd
}
func (c *commandable) Exists(key string) *BoolCmd {
cmd := NewBoolCmd("EXISTS", key)
c.Process(cmd)
return cmd
}
func (c *commandable) Expire(key string, expiration time.Duration) *BoolCmd {
cmd := NewBoolCmd("EXPIRE", key, formatSec(expiration))
c.Process(cmd)
return cmd
}
func (c *commandable) ExpireAt(key string, tm time.Time) *BoolCmd {
cmd := NewBoolCmd("EXPIREAT", key, tm.Unix())
c.Process(cmd)
return cmd
}
func (c *commandable) Keys(pattern string) *StringSliceCmd {
cmd := NewStringSliceCmd("KEYS", pattern)
c.Process(cmd)
return cmd
}
func (c *commandable) Migrate(host, port, key string, db int64, timeout time.Duration) *StatusCmd {
cmd := NewStatusCmd(
"MIGRATE",
host,
port,
key,
db,
formatMs(timeout),
)
cmd._clusterKeyPos = 3
cmd.setReadTimeout(readTimeout(timeout))
c.Process(cmd)
return cmd
}
func (c *commandable) Move(key string, db int64) *BoolCmd {
cmd := NewBoolCmd("MOVE", key, db)
c.Process(cmd)
return cmd
}
func (c *commandable) ObjectRefCount(keys ...string) *IntCmd {
args := make([]interface{}, 2+len(keys))
args[0] = "OBJECT"
args[1] = "REFCOUNT"
for i, key := range keys {
args[2+i] = key
}
cmd := NewIntCmd(args...)
cmd._clusterKeyPos = 2
c.Process(cmd)
return cmd
}
func (c *commandable) ObjectEncoding(keys ...string) *StringCmd {
args := make([]interface{}, 2+len(keys))
args[0] = "OBJECT"
args[1] = "ENCODING"
for i, key := range keys {
args[2+i] = key
}
cmd := NewStringCmd(args...)
cmd._clusterKeyPos = 2
c.Process(cmd)
return cmd
}
func (c *commandable) ObjectIdleTime(keys ...string) *DurationCmd {
args := make([]interface{}, 2+len(keys))
args[0] = "OBJECT"
args[1] = "IDLETIME"
for i, key := range keys {
args[2+i] = key
}
cmd := NewDurationCmd(time.Second, args...)
cmd._clusterKeyPos = 2
c.Process(cmd)
return cmd
}
func (c *commandable) Persist(key string) *BoolCmd {
cmd := NewBoolCmd("PERSIST", key)
c.Process(cmd)
return cmd
}
func (c *commandable) PExpire(key string, expiration time.Duration) *BoolCmd {
cmd := NewBoolCmd("PEXPIRE", key, formatMs(expiration))
c.Process(cmd)
return cmd
}
func (c *commandable) PExpireAt(key string, tm time.Time) *BoolCmd {
cmd := NewBoolCmd(
"PEXPIREAT",
key,
tm.UnixNano()/int64(time.Millisecond),
)
c.Process(cmd)
return cmd
}
func (c *commandable) PTTL(key string) *DurationCmd {
cmd := NewDurationCmd(time.Millisecond, "PTTL", key)
c.Process(cmd)
return cmd
}
func (c *commandable) RandomKey() *StringCmd {
cmd := NewStringCmd("RANDOMKEY")
c.Process(cmd)
return cmd
}
func (c *commandable) Rename(key, newkey string) *StatusCmd {
cmd := NewStatusCmd("RENAME", key, newkey)
c.Process(cmd)
return cmd
}
func (c *commandable) RenameNX(key, newkey string) *BoolCmd {
cmd := NewBoolCmd("RENAMENX", key, newkey)
c.Process(cmd)
return cmd
}
func (c *commandable) Restore(key string, ttl time.Duration, value string) *StatusCmd {
cmd := NewStatusCmd(
"RESTORE",
key,
formatMs(ttl),
value,
)
c.Process(cmd)
return cmd
}
func (c *commandable) RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd {
cmd := NewStatusCmd(
"RESTORE",
key,
formatMs(ttl),
value,
"REPLACE",
)
c.Process(cmd)
return cmd
}
type Sort struct {
By string
Offset, Count float64
Get []string
Order string
IsAlpha bool
Store string
}
func (c *commandable) Sort(key string, sort Sort) *StringSliceCmd {
args := []interface{}{"SORT", key}
if sort.By != "" {
args = append(args, "BY", sort.By)
}
if sort.Offset != 0 || sort.Count != 0 {
args = append(args, "LIMIT", sort.Offset, sort.Count)
}
for _, get := range sort.Get {
args = append(args, "GET", get)
}
if sort.Order != "" {
args = append(args, sort.Order)
}
if sort.IsAlpha {
args = append(args, "ALPHA")
}
if sort.Store != "" {
args = append(args, "STORE", sort.Store)
}
cmd := NewStringSliceCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) TTL(key string) *DurationCmd {
cmd := NewDurationCmd(time.Second, "TTL", key)
c.Process(cmd)
return cmd
}
func (c *commandable) Type(key string) *StatusCmd {
cmd := NewStatusCmd("TYPE", key)
c.Process(cmd)
return cmd
}
func (c *commandable) Scan(cursor int64, match string, count int64) *ScanCmd {
args := []interface{}{"SCAN", cursor}
if match != "" {
args = append(args, "MATCH", match)
}
if count > 0 {
args = append(args, "COUNT", count)
}
cmd := NewScanCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) SScan(key string, cursor int64, match string, count int64) *ScanCmd {
args := []interface{}{"SSCAN", key, cursor}
if match != "" {
args = append(args, "MATCH", match)
}
if count > 0 {
args = append(args, "COUNT", count)
}
cmd := NewScanCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) HScan(key string, cursor int64, match string, count int64) *ScanCmd {
args := []interface{}{"HSCAN", key, cursor}
if match != "" {
args = append(args, "MATCH", match)
}
if count > 0 {
args = append(args, "COUNT", count)
}
cmd := NewScanCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) ZScan(key string, cursor int64, match string, count int64) *ScanCmd {
args := []interface{}{"ZSCAN", key, cursor}
if match != "" {
args = append(args, "MATCH", match)
}
if count > 0 {
args = append(args, "COUNT", count)
}
cmd := NewScanCmd(args...)
c.Process(cmd)
return cmd
}
//------------------------------------------------------------------------------
func (c *commandable) Append(key, value string) *IntCmd {
cmd := NewIntCmd("APPEND", key, value)
c.Process(cmd)
return cmd
}
type BitCount struct {
Start, End int64
}
func (c *commandable) BitCount(key string, bitCount *BitCount) *IntCmd {
args := []interface{}{"BITCOUNT", key}
if bitCount != nil {
args = append(
args,
bitCount.Start,
bitCount.End,
)
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) bitOp(op, destKey string, keys ...string) *IntCmd {
args := make([]interface{}, 3+len(keys))
args[0] = "BITOP"
args[1] = op
args[2] = destKey
for i, key := range keys {
args[3+i] = key
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) BitOpAnd(destKey string, keys ...string) *IntCmd {
return c.bitOp("AND", destKey, keys...)
}
func (c *commandable) BitOpOr(destKey string, keys ...string) *IntCmd {
return c.bitOp("OR", destKey, keys...)
}
func (c *commandable) BitOpXor(destKey string, keys ...string) *IntCmd {
return c.bitOp("XOR", destKey, keys...)
}
func (c *commandable) BitOpNot(destKey string, key string) *IntCmd {
return c.bitOp("NOT", destKey, key)
}
func (c *commandable) BitPos(key string, bit int64, pos ...int64) *IntCmd {
args := make([]interface{}, 3+len(pos))
args[0] = "BITPOS"
args[1] = key
args[2] = bit
switch len(pos) {
case 0:
case 1:
args[3] = pos[0]
case 2:
args[3] = pos[0]
args[4] = pos[1]
default:
panic("too many arguments")
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) Decr(key string) *IntCmd {
cmd := NewIntCmd("DECR", key)
c.Process(cmd)
return cmd
}
func (c *commandable) DecrBy(key string, decrement int64) *IntCmd {
cmd := NewIntCmd("DECRBY", key, decrement)
c.Process(cmd)
return cmd
}
func (c *commandable) Get(key string) *StringCmd {
cmd := NewStringCmd("GET", key)
c.Process(cmd)
return cmd
}
func (c *commandable) GetBit(key string, offset int64) *IntCmd {
cmd := NewIntCmd("GETBIT", key, offset)
c.Process(cmd)
return cmd
}
func (c *commandable) GetRange(key string, start, end int64) *StringCmd {
cmd := NewStringCmd("GETRANGE", key, start, end)
c.Process(cmd)
return cmd
}
func (c *commandable) GetSet(key string, value interface{}) *StringCmd {
cmd := NewStringCmd("GETSET", key, value)
c.Process(cmd)
return cmd
}
func (c *commandable) Incr(key string) *IntCmd {
cmd := NewIntCmd("INCR", key)
c.Process(cmd)
return cmd
}
func (c *commandable) IncrBy(key string, value int64) *IntCmd {
cmd := NewIntCmd("INCRBY", key, value)
c.Process(cmd)
return cmd
}
func (c *commandable) IncrByFloat(key string, value float64) *FloatCmd {
cmd := NewFloatCmd("INCRBYFLOAT", key, value)
c.Process(cmd)
return cmd
}
func (c *commandable) MGet(keys ...string) *SliceCmd {
args := make([]interface{}, 1+len(keys))
args[0] = "MGET"
for i, key := range keys {
args[1+i] = key
}
cmd := NewSliceCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) MSet(pairs ...string) *StatusCmd {
args := make([]interface{}, 1+len(pairs))
args[0] = "MSET"
for i, pair := range pairs {
args[1+i] = pair
}
cmd := NewStatusCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) MSetNX(pairs ...string) *BoolCmd {
args := make([]interface{}, 1+len(pairs))
args[0] = "MSETNX"
for i, pair := range pairs {
args[1+i] = pair
}
cmd := NewBoolCmd(args...)
c.Process(cmd)
return cmd
}
// Redis `SET key value [expiration]` command.
//
// Zero expiration means the key has no expiration time.
func (c *commandable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd {
args := make([]interface{}, 3, 5)
args[0] = "SET"
args[1] = key
args[2] = value
if expiration > 0 {
if usePrecise(expiration) {
args = append(args, "PX", formatMs(expiration))
} else {
args = append(args, "EX", formatSec(expiration))
}
}
cmd := NewStatusCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) SetBit(key string, offset int64, value int) *IntCmd {
cmd := NewIntCmd(
"SETBIT",
key,
offset,
value,
)
c.Process(cmd)
return cmd
}
// Redis `SET key value [expiration] NX` command.
//
// Zero expiration means the key has no expiration time.
func (c *commandable) SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd {
var cmd *BoolCmd
if expiration == 0 {
// Use old `SETNX` to support old Redis versions.
cmd = NewBoolCmd("SETNX", key, value)
} else {
if usePrecise(expiration) {
cmd = NewBoolCmd("SET", key, value, "PX", formatMs(expiration), "NX")
} else {
cmd = NewBoolCmd("SET", key, value, "EX", formatSec(expiration), "NX")
}
}
c.Process(cmd)
return cmd
}
// Redis `SET key value [expiration] XX` command.
//
// Zero expiration means the key has no expiration time.
func (c *Client) SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd {
var cmd *BoolCmd
if usePrecise(expiration) {
cmd = NewBoolCmd("SET", key, value, "PX", formatMs(expiration), "XX")
} else {
cmd = NewBoolCmd("SET", key, value, "EX", formatSec(expiration), "XX")
}
c.Process(cmd)
return cmd
}
func (c *commandable) SetRange(key string, offset int64, value string) *IntCmd {
cmd := NewIntCmd("SETRANGE", key, offset, value)
c.Process(cmd)
return cmd
}
func (c *commandable) StrLen(key string) *IntCmd {
cmd := NewIntCmd("STRLEN", key)
c.Process(cmd)
return cmd
}
//------------------------------------------------------------------------------
func (c *commandable) HDel(key string, fields ...string) *IntCmd {
args := make([]interface{}, 2+len(fields))
args[0] = "HDEL"
args[1] = key
for i, field := range fields {
args[2+i] = field
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) HExists(key, field string) *BoolCmd {
cmd := NewBoolCmd("HEXISTS", key, field)
c.Process(cmd)
return cmd
}
func (c *commandable) HGet(key, field string) *StringCmd {
cmd := NewStringCmd("HGET", key, field)
c.Process(cmd)
return cmd
}
func (c *commandable) HGetAll(key string) *StringSliceCmd {
cmd := NewStringSliceCmd("HGETALL", key)
c.Process(cmd)
return cmd
}
func (c *commandable) HGetAllMap(key string) *StringStringMapCmd {
cmd := NewStringStringMapCmd("HGETALL", key)
c.Process(cmd)
return cmd
}
func (c *commandable) HIncrBy(key, field string, incr int64) *IntCmd {
cmd := NewIntCmd("HINCRBY", key, field, incr)
c.Process(cmd)
return cmd
}
func (c *commandable) HIncrByFloat(key, field string, incr float64) *FloatCmd {
cmd := NewFloatCmd("HINCRBYFLOAT", key, field, incr)
c.Process(cmd)
return cmd
}
func (c *commandable) HKeys(key string) *StringSliceCmd {
cmd := NewStringSliceCmd("HKEYS", key)
c.Process(cmd)
return cmd
}
func (c *commandable) HLen(key string) *IntCmd {
cmd := NewIntCmd("HLEN", key)
c.Process(cmd)
return cmd
}
func (c *commandable) HMGet(key string, fields ...string) *SliceCmd {
args := make([]interface{}, 2+len(fields))
args[0] = "HMGET"
args[1] = key
for i, field := range fields {
args[2+i] = field
}
cmd := NewSliceCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) HMSet(key, field, value string, pairs ...string) *StatusCmd {
args := make([]interface{}, 4+len(pairs))
args[0] = "HMSET"
args[1] = key
args[2] = field
args[3] = value
for i, pair := range pairs {
args[4+i] = pair
}
cmd := NewStatusCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) HSet(key, field, value string) *BoolCmd {
cmd := NewBoolCmd("HSET", key, field, value)
c.Process(cmd)
return cmd
}
func (c *commandable) HSetNX(key, field, value string) *BoolCmd {
cmd := NewBoolCmd("HSETNX", key, field, value)
c.Process(cmd)
return cmd
}
func (c *commandable) HVals(key string) *StringSliceCmd {
cmd := NewStringSliceCmd("HVALS", key)
c.Process(cmd)
return cmd
}
//------------------------------------------------------------------------------
func (c *commandable) BLPop(timeout time.Duration, keys ...string) *StringSliceCmd {
args := make([]interface{}, 2+len(keys))
args[0] = "BLPOP"
for i, key := range keys {
args[1+i] = key
}
args[len(args)-1] = formatSec(timeout)
cmd := NewStringSliceCmd(args...)
cmd.setReadTimeout(readTimeout(timeout))
c.Process(cmd)
return cmd
}
func (c *commandable) BRPop(timeout time.Duration, keys ...string) *StringSliceCmd {
args := make([]interface{}, 2+len(keys))
args[0] = "BRPOP"
for i, key := range keys {
args[1+i] = key
}
args[len(args)-1] = formatSec(timeout)
cmd := NewStringSliceCmd(args...)
cmd.setReadTimeout(readTimeout(timeout))
c.Process(cmd)
return cmd
}
func (c *commandable) BRPopLPush(source, destination string, timeout time.Duration) *StringCmd {
cmd := NewStringCmd(
"BRPOPLPUSH",
source,
destination,
formatSec(timeout),
)
cmd.setReadTimeout(readTimeout(timeout))
c.Process(cmd)
return cmd
}
func (c *commandable) LIndex(key string, index int64) *StringCmd {
cmd := NewStringCmd("LINDEX", key, index)
c.Process(cmd)
return cmd
}
func (c *commandable) LInsert(key, op, pivot, value string) *IntCmd {
cmd := NewIntCmd("LINSERT", key, op, pivot, value)
c.Process(cmd)
return cmd
}
func (c *commandable) LLen(key string) *IntCmd {
cmd := NewIntCmd("LLEN", key)
c.Process(cmd)
return cmd
}
func (c *commandable) LPop(key string) *StringCmd {
cmd := NewStringCmd("LPOP", key)
c.Process(cmd)
return cmd
}
func (c *commandable) LPush(key string, values ...string) *IntCmd {
args := make([]interface{}, 2+len(values))
args[0] = "LPUSH"
args[1] = key
for i, value := range values {
args[2+i] = value
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) LPushX(key, value string) *IntCmd {
cmd := NewIntCmd("LPUSHX", key, value)
c.Process(cmd)
return cmd
}
func (c *commandable) LRange(key string, start, stop int64) *StringSliceCmd {
cmd := NewStringSliceCmd(
"LRANGE",
key,
start,
stop,
)
c.Process(cmd)
return cmd
}
func (c *commandable) LRem(key string, count int64, value string) *IntCmd {
cmd := NewIntCmd("LREM", key, count, value)
c.Process(cmd)
return cmd
}
func (c *commandable) LSet(key string, index int64, value string) *StatusCmd {
cmd := NewStatusCmd("LSET", key, index, value)
c.Process(cmd)
return cmd
}
func (c *commandable) LTrim(key string, start, stop int64) *StatusCmd {
cmd := NewStatusCmd(
"LTRIM",
key,
start,
stop,
)
c.Process(cmd)
return cmd
}
func (c *commandable) RPop(key string) *StringCmd {
cmd := NewStringCmd("RPOP", key)
c.Process(cmd)
return cmd
}
func (c *commandable) RPopLPush(source, destination string) *StringCmd {
cmd := NewStringCmd("RPOPLPUSH", source, destination)
c.Process(cmd)
return cmd
}
func (c *commandable) RPush(key string, values ...string) *IntCmd {
args := make([]interface{}, 2+len(values))
args[0] = "RPUSH"
args[1] = key
for i, value := range values {
args[2+i] = value
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) RPushX(key string, value string) *IntCmd {
cmd := NewIntCmd("RPUSHX", key, value)
c.Process(cmd)
return cmd
}
//------------------------------------------------------------------------------
func (c *commandable) SAdd(key string, members ...string) *IntCmd {
args := make([]interface{}, 2+len(members))
args[0] = "SADD"
args[1] = key
for i, member := range members {
args[2+i] = member
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) SCard(key string) *IntCmd {
cmd := NewIntCmd("SCARD", key)
c.Process(cmd)
return cmd
}
func (c *commandable) SDiff(keys ...string) *StringSliceCmd {
args := make([]interface{}, 1+len(keys))
args[0] = "SDIFF"
for i, key := range keys {
args[1+i] = key
}
cmd := NewStringSliceCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) SDiffStore(destination string, keys ...string) *IntCmd {
args := make([]interface{}, 2+len(keys))
args[0] = "SDIFFSTORE"
args[1] = destination
for i, key := range keys {
args[2+i] = key
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) SInter(keys ...string) *StringSliceCmd {
args := make([]interface{}, 1+len(keys))
args[0] = "SINTER"
for i, key := range keys {
args[1+i] = key
}
cmd := NewStringSliceCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) SInterStore(destination string, keys ...string) *IntCmd {
args := make([]interface{}, 2+len(keys))
args[0] = "SINTERSTORE"
args[1] = destination
for i, key := range keys {
args[2+i] = key
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) SIsMember(key, member string) *BoolCmd {
cmd := NewBoolCmd("SISMEMBER", key, member)
c.Process(cmd)
return cmd
}
func (c *commandable) SMembers(key string) *StringSliceCmd {
cmd := NewStringSliceCmd("SMEMBERS", key)
c.Process(cmd)
return cmd
}
func (c *commandable) SMove(source, destination, member string) *BoolCmd {
cmd := NewBoolCmd("SMOVE", source, destination, member)
c.Process(cmd)
return cmd
}
func (c *commandable) SPop(key string) *StringCmd {
cmd := NewStringCmd("SPOP", key)
c.Process(cmd)
return cmd
}
// Redis `SRANDMEMBER key` command.
func (c *commandable) SRandMember(key string) *StringCmd {
cmd := NewStringCmd("SRANDMEMBER", key)
c.Process(cmd)
return cmd
}
// Redis `SRANDMEMBER key count` command.
func (c *commandable) SRandMemberN(key string, count int64) *StringSliceCmd {
cmd := NewStringSliceCmd("SRANDMEMBER", key, count)
c.Process(cmd)
return cmd
}
func (c *commandable) SRem(key string, members ...string) *IntCmd {
args := make([]interface{}, 2+len(members))
args[0] = "SREM"
args[1] = key
for i, member := range members {
args[2+i] = member
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) SUnion(keys ...string) *StringSliceCmd {
args := make([]interface{}, 1+len(keys))
args[0] = "SUNION"
for i, key := range keys {
args[1+i] = key
}
cmd := NewStringSliceCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) SUnionStore(destination string, keys ...string) *IntCmd {
args := make([]interface{}, 2+len(keys))
args[0] = "SUNIONSTORE"
args[1] = destination
for i, key := range keys {
args[2+i] = key
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
//------------------------------------------------------------------------------
// Sorted set member.
type Z struct {
Score float64
Member interface{}
}
// Sorted set store operation.
type ZStore struct {
Weights []int64
// Can be SUM, MIN or MAX.
Aggregate string
}
func (c *commandable) zAdd(a []interface{}, n int, members ...Z) *IntCmd {
for i, m := range members {
a[n+2*i] = m.Score
a[n+2*i+1] = m.Member
}
cmd := NewIntCmd(a...)
c.Process(cmd)
return cmd
}
// Redis `ZADD key score member [score member ...]` command.
func (c *commandable) ZAdd(key string, members ...Z) *IntCmd {
const n = 2
a := make([]interface{}, n+2*len(members))
a[0], a[1] = "ZADD", key
return c.zAdd(a, n, members...)
}
// Redis `ZADD key NX score member [score member ...]` command.
func (c *commandable) ZAddNX(key string, members ...Z) *IntCmd {
const n = 3
a := make([]interface{}, n+2*len(members))
a[0], a[1], a[2] = "ZADD", key, "NX"
return c.zAdd(a, n, members...)
}
// Redis `ZADD key XX score member [score member ...]` command.
func (c *commandable) ZAddXX(key string, members ...Z) *IntCmd {
const n = 3
a := make([]interface{}, n+2*len(members))
a[0], a[1], a[2] = "ZADD", key, "XX"
return c.zAdd(a, n, members...)
}
// Redis `ZADD key CH score member [score member ...]` command.
func (c *commandable) ZAddCh(key string, members ...Z) *IntCmd {
const n = 3
a := make([]interface{}, n+2*len(members))
a[0], a[1], a[2] = "ZADD", key, "CH"
return c.zAdd(a, n, members...)
}
// Redis `ZADD key NX CH score member [score member ...]` command.
func (c *commandable) ZAddNXCh(key string, members ...Z) *IntCmd {
const n = 4
a := make([]interface{}, n+2*len(members))
a[0], a[1], a[2], a[3] = "ZADD", key, "NX", "CH"
return c.zAdd(a, n, members...)
}
// Redis `ZADD key XX CH score member [score member ...]` command.
func (c *commandable) ZAddXXCh(key string, members ...Z) *IntCmd {
const n = 4
a := make([]interface{}, n+2*len(members))
a[0], a[1], a[2], a[3] = "ZADD", key, "XX", "CH"
return c.zAdd(a, n, members...)
}
func (c *commandable) zIncr(a []interface{}, n int, members ...Z) *FloatCmd {
for i, m := range members {
a[n+2*i] = m.Score
a[n+2*i+1] = m.Member
}
cmd := NewFloatCmd(a...)
c.Process(cmd)
return cmd
}
// Redis `ZADD key INCR score member` command.
func (c *commandable) ZIncr(key string, member Z) *FloatCmd {
const n = 3
a := make([]interface{}, n+2)
a[0], a[1], a[2] = "ZADD", key, "INCR"
return c.zIncr(a, n, member)
}
// Redis `ZADD key NX INCR score member` command.
func (c *commandable) ZIncrNX(key string, member Z) *FloatCmd {
const n = 4
a := make([]interface{}, n+2)
a[0], a[1], a[2], a[3] = "ZADD", key, "INCR", "NX"
return c.zIncr(a, n, member)
}
// Redis `ZADD key XX INCR score member` command.
func (c *commandable) ZIncrXX(key string, member Z) *FloatCmd {
const n = 4
a := make([]interface{}, n+2)
a[0], a[1], a[2], a[3] = "ZADD", key, "INCR", "XX"
return c.zIncr(a, n, member)
}
func (c *commandable) ZCard(key string) *IntCmd {
cmd := NewIntCmd("ZCARD", key)
c.Process(cmd)
return cmd
}
func (c *commandable) ZCount(key, min, max string) *IntCmd {
cmd := NewIntCmd("ZCOUNT", key, min, max)
c.Process(cmd)
return cmd
}
func (c *commandable) ZIncrBy(key string, increment float64, member string) *FloatCmd {
cmd := NewFloatCmd("ZINCRBY", key, increment, member)
c.Process(cmd)
return cmd
}
func (c *commandable) ZInterStore(
destination string,
store ZStore,
keys ...string,
) *IntCmd {
args := make([]interface{}, 3+len(keys))
args[0] = "ZINTERSTORE"
args[1] = destination
args[2] = strconv.Itoa(len(keys))
for i, key := range keys {
args[3+i] = key
}
if len(store.Weights) > 0 {
args = append(args, "WEIGHTS")
for _, weight := range store.Weights {
args = append(args, weight)
}
}
if store.Aggregate != "" {
args = append(args, "AGGREGATE", store.Aggregate)
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) zRange(key string, start, stop int64, withScores bool) *StringSliceCmd {
args := []interface{}{
"ZRANGE",
key,
start,
stop,
}
if withScores {
args = append(args, "WITHSCORES")
}
cmd := NewStringSliceCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) ZRange(key string, start, stop int64) *StringSliceCmd {
return c.zRange(key, start, stop, false)
}
func (c *commandable) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd {
cmd := NewZSliceCmd("ZRANGE", key, start, stop, "WITHSCORES")
c.Process(cmd)
return cmd
}
// TODO: Rename to something more generic in v4
type ZRangeByScore struct {
Min, Max string
Offset, Count int64
}
func (c *commandable) zRangeBy(zcmd, key string, opt ZRangeByScore, withScores bool) *StringSliceCmd {
args := []interface{}{zcmd, key, opt.Min, opt.Max}
if withScores {
args = append(args, "WITHSCORES")
}
if opt.Offset != 0 || opt.Count != 0 {
args = append(
args,
"LIMIT",
opt.Offset,
opt.Count,
)
}
cmd := NewStringSliceCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) ZRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd {
return c.zRangeBy("ZRANGEBYSCORE", key, opt, false)
}
func (c *commandable) ZRangeByLex(key string, opt ZRangeByScore) *StringSliceCmd {
return c.zRangeBy("ZRANGEBYLEX", key, opt, false)
}
func (c *commandable) ZRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd {
args := []interface{}{"ZRANGEBYSCORE", key, opt.Min, opt.Max, "WITHSCORES"}
if opt.Offset != 0 || opt.Count != 0 {
args = append(
args,
"LIMIT",
opt.Offset,
opt.Count,
)
}
cmd := NewZSliceCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) ZRank(key, member string) *IntCmd {
cmd := NewIntCmd("ZRANK", key, member)
c.Process(cmd)
return cmd
}
func (c *commandable) ZRem(key string, members ...string) *IntCmd {
args := make([]interface{}, 2+len(members))
args[0] = "ZREM"
args[1] = key
for i, member := range members {
args[2+i] = member
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) ZRemRangeByRank(key string, start, stop int64) *IntCmd {
cmd := NewIntCmd(
"ZREMRANGEBYRANK",
key,
start,
stop,
)
c.Process(cmd)
return cmd
}
func (c *commandable) ZRemRangeByScore(key, min, max string) *IntCmd {
cmd := NewIntCmd("ZREMRANGEBYSCORE", key, min, max)
c.Process(cmd)
return cmd
}
func (c *commandable) ZRevRange(key string, start, stop int64) *StringSliceCmd {
cmd := NewStringSliceCmd("ZREVRANGE", key, start, stop)
c.Process(cmd)
return cmd
}
func (c *commandable) ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd {
cmd := NewZSliceCmd("ZREVRANGE", key, start, stop, "WITHSCORES")
c.Process(cmd)
return cmd
}
func (c *commandable) zRevRangeBy(zcmd, key string, opt ZRangeByScore) *StringSliceCmd {
args := []interface{}{zcmd, key, opt.Max, opt.Min}
if opt.Offset != 0 || opt.Count != 0 {
args = append(
args,
"LIMIT",
opt.Offset,
opt.Count,
)
}
cmd := NewStringSliceCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) ZRevRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd {
return c.zRevRangeBy("ZREVRANGEBYSCORE", key, opt)
}
func (c commandable) ZRevRangeByLex(key string, opt ZRangeByScore) *StringSliceCmd {
return c.zRevRangeBy("ZREVRANGEBYLEX", key, opt)
}
func (c *commandable) ZRevRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd {
args := []interface{}{"ZREVRANGEBYSCORE", key, opt.Max, opt.Min, "WITHSCORES"}
if opt.Offset != 0 || opt.Count != 0 {
args = append(
args,
"LIMIT",
opt.Offset,
opt.Count,
)
}
cmd := NewZSliceCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) ZRevRank(key, member string) *IntCmd {
cmd := NewIntCmd("ZREVRANK", key, member)
c.Process(cmd)
return cmd
}
func (c *commandable) ZScore(key, member string) *FloatCmd {
cmd := NewFloatCmd("ZSCORE", key, member)
c.Process(cmd)
return cmd
}
func (c *commandable) ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd {
args := make([]interface{}, 3+len(keys))
args[0] = "ZUNIONSTORE"
args[1] = dest
args[2] = strconv.Itoa(len(keys))
for i, key := range keys {
args[3+i] = key
}
if len(store.Weights) > 0 {
args = append(args, "WEIGHTS")
for _, weight := range store.Weights {
args = append(args, weight)
}
}
if store.Aggregate != "" {
args = append(args, "AGGREGATE", store.Aggregate)
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
//------------------------------------------------------------------------------
func (c *commandable) PFAdd(key string, fields ...string) *IntCmd {
args := make([]interface{}, 2+len(fields))
args[0] = "PFADD"
args[1] = key
for i, field := range fields {
args[2+i] = field
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) PFCount(key string) *IntCmd {
cmd := NewIntCmd("PFCOUNT", key)
c.Process(cmd)
return cmd
}
func (c *commandable) PFMerge(dest string, keys ...string) *StatusCmd {
args := make([]interface{}, 2+len(keys))
args[0] = "PFMERGE"
args[1] = dest
for i, key := range keys {
args[2+i] = key
}
cmd := NewStatusCmd(args...)
c.Process(cmd)
return cmd
}
//------------------------------------------------------------------------------
func (c *commandable) BgRewriteAOF() *StatusCmd {
cmd := NewStatusCmd("BGREWRITEAOF")
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) BgSave() *StatusCmd {
cmd := NewStatusCmd("BGSAVE")
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) ClientKill(ipPort string) *StatusCmd {
cmd := NewStatusCmd("CLIENT", "KILL", ipPort)
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) ClientList() *StringCmd {
cmd := NewStringCmd("CLIENT", "LIST")
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) ClientPause(dur time.Duration) *BoolCmd {
cmd := NewBoolCmd("CLIENT", "PAUSE", formatMs(dur))
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
// ClientSetName assigns a name to the one of many connections in the pool.
func (c *commandable) ClientSetName(name string) *BoolCmd {
cmd := NewBoolCmd("CLIENT", "SETNAME", name)
c.Process(cmd)
return cmd
}
// ClientGetName returns the name of the one of many connections in the pool.
func (c *Client) ClientGetName() *StringCmd {
cmd := NewStringCmd("CLIENT", "GETNAME")
c.Process(cmd)
return cmd
}
func (c *commandable) ConfigGet(parameter string) *SliceCmd {
cmd := NewSliceCmd("CONFIG", "GET", parameter)
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) ConfigResetStat() *StatusCmd {
cmd := NewStatusCmd("CONFIG", "RESETSTAT")
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) ConfigSet(parameter, value string) *StatusCmd {
cmd := NewStatusCmd("CONFIG", "SET", parameter, value)
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) DbSize() *IntCmd {
cmd := NewIntCmd("DBSIZE")
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) FlushAll() *StatusCmd {
cmd := newKeylessStatusCmd("FLUSHALL")
c.Process(cmd)
return cmd
}
func (c *commandable) FlushDb() *StatusCmd {
cmd := newKeylessStatusCmd("FLUSHDB")
c.Process(cmd)
return cmd
}
func (c *commandable) Info() *StringCmd {
cmd := NewStringCmd("INFO")
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) LastSave() *IntCmd {
cmd := NewIntCmd("LASTSAVE")
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) Save() *StatusCmd {
cmd := newKeylessStatusCmd("SAVE")
c.Process(cmd)
return cmd
}
func (c *commandable) shutdown(modifier string) *StatusCmd {
var args []interface{}
if modifier == "" {
args = []interface{}{"SHUTDOWN"}
} else {
args = []interface{}{"SHUTDOWN", modifier}
}
cmd := newKeylessStatusCmd(args...)
c.Process(cmd)
if err := cmd.Err(); err != nil {
if err == io.EOF {
// Server quit as expected.
cmd.err = nil
}
} else {
// Server did not quit. String reply contains the reason.
cmd.err = errorf(cmd.val)
cmd.val = ""
}
return cmd
}
func (c *commandable) Shutdown() *StatusCmd {
return c.shutdown("")
}
func (c *commandable) ShutdownSave() *StatusCmd {
return c.shutdown("SAVE")
}
func (c *commandable) ShutdownNoSave() *StatusCmd {
return c.shutdown("NOSAVE")
}
func (c *commandable) SlaveOf(host, port string) *StatusCmd {
cmd := newKeylessStatusCmd("SLAVEOF", host, port)
c.Process(cmd)
return cmd
}
func (c *commandable) SlowLog() {
panic("not implemented")
}
func (c *commandable) Sync() {
panic("not implemented")
}
func (c *commandable) Time() *StringSliceCmd {
cmd := NewStringSliceCmd("TIME")
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
//------------------------------------------------------------------------------
func (c *commandable) Eval(script string, keys []string, args []string) *Cmd {
cmdArgs := make([]interface{}, 3+len(keys)+len(args))
cmdArgs[0] = "EVAL"
cmdArgs[1] = script
cmdArgs[2] = strconv.Itoa(len(keys))
for i, key := range keys {
cmdArgs[3+i] = key
}
pos := 3 + len(keys)
for i, arg := range args {
cmdArgs[pos+i] = arg
}
cmd := NewCmd(cmdArgs...)
if len(keys) > 0 {
cmd._clusterKeyPos = 3
}
c.Process(cmd)
return cmd
}
func (c *commandable) EvalSha(sha1 string, keys []string, args []string) *Cmd {
cmdArgs := make([]interface{}, 3+len(keys)+len(args))
cmdArgs[0] = "EVALSHA"
cmdArgs[1] = sha1
cmdArgs[2] = strconv.Itoa(len(keys))
for i, key := range keys {
cmdArgs[3+i] = key
}
pos := 3 + len(keys)
for i, arg := range args {
cmdArgs[pos+i] = arg
}
cmd := NewCmd(cmdArgs...)
if len(keys) > 0 {
cmd._clusterKeyPos = 3
}
c.Process(cmd)
return cmd
}
func (c *commandable) ScriptExists(scripts ...string) *BoolSliceCmd {
args := make([]interface{}, 2+len(scripts))
args[0] = "SCRIPT"
args[1] = "EXISTS"
for i, script := range scripts {
args[2+i] = script
}
cmd := NewBoolSliceCmd(args...)
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) ScriptFlush() *StatusCmd {
cmd := newKeylessStatusCmd("SCRIPT", "FLUSH")
c.Process(cmd)
return cmd
}
func (c *commandable) ScriptKill() *StatusCmd {
cmd := newKeylessStatusCmd("SCRIPT", "KILL")
c.Process(cmd)
return cmd
}
func (c *commandable) ScriptLoad(script string) *StringCmd {
cmd := NewStringCmd("SCRIPT", "LOAD", script)
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
//------------------------------------------------------------------------------
func (c *commandable) DebugObject(key string) *StringCmd {
cmd := NewStringCmd("DEBUG", "OBJECT", key)
cmd._clusterKeyPos = 2
c.Process(cmd)
return cmd
}
//------------------------------------------------------------------------------
func (c *commandable) PubSubChannels(pattern string) *StringSliceCmd {
args := []interface{}{"PUBSUB", "CHANNELS"}
if pattern != "*" {
args = append(args, pattern)
}
cmd := NewStringSliceCmd(args...)
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) PubSubNumSub(channels ...string) *StringIntMapCmd {
args := make([]interface{}, 2+len(channels))
args[0] = "PUBSUB"
args[1] = "NUMSUB"
for i, channel := range channels {
args[2+i] = channel
}
cmd := NewStringIntMapCmd(args...)
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) PubSubNumPat() *IntCmd {
cmd := NewIntCmd("PUBSUB", "NUMPAT")
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
//------------------------------------------------------------------------------
func (c *commandable) ClusterSlots() *ClusterSlotCmd {
cmd := NewClusterSlotCmd("CLUSTER", "slots")
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) ClusterNodes() *StringCmd {
cmd := NewStringCmd("CLUSTER", "nodes")
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) ClusterMeet(host, port string) *StatusCmd {
cmd := newKeylessStatusCmd("CLUSTER", "meet", host, port)
c.Process(cmd)
return cmd
}
func (c *commandable) ClusterReplicate(nodeID string) *StatusCmd {
cmd := newKeylessStatusCmd("CLUSTER", "replicate", nodeID)
c.Process(cmd)
return cmd
}
func (c *commandable) ClusterInfo() *StringCmd {
cmd := NewStringCmd("CLUSTER", "info")
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) ClusterFailover() *StatusCmd {
cmd := newKeylessStatusCmd("CLUSTER", "failover")
c.Process(cmd)
return cmd
}
func (c *commandable) ClusterAddSlots(slots ...int) *StatusCmd {
args := make([]interface{}, 2+len(slots))
args[0] = "CLUSTER"
args[1] = "ADDSLOTS"
for i, num := range slots {
args[2+i] = strconv.Itoa(num)
}
cmd := newKeylessStatusCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) ClusterAddSlotsRange(min, max int) *StatusCmd {
size := max - min + 1
slots := make([]int, size)
for i := 0; i < size; i++ {
slots[i] = min + i
}
return c.ClusterAddSlots(slots...)
}
//------------------------------------------------------------------------------
func (c *commandable) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd {
args := make([]interface{}, 2+3*len(geoLocation))
args[0] = "GEOADD"
args[1] = key
for i, eachLoc := range geoLocation {
args[2+3*i] = eachLoc.Longitude
args[2+3*i+1] = eachLoc.Latitude
args[2+3*i+2] = eachLoc.Name
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd {
cmd := NewGeoLocationCmd(query, "GEORADIUS", key, longitude, latitude)
c.Process(cmd)
return cmd
}
func (c *commandable) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd {
cmd := NewGeoLocationCmd(query, "GEORADIUSBYMEMBER", key, member)
c.Process(cmd)
return cmd
}
func (c *commandable) GeoDist(key string, member1, member2, unit string) *FloatCmd {
if unit == "" {
unit = "km"
}
cmd := NewFloatCmd("GEODIST", key, member1, member2, unit)
c.Process(cmd)
return cmd
}
func (c *commandable) GeoHash(key string, members ...string) *StringSliceCmd {
args := make([]interface{}, 2+len(members))
args[0] = "GEOHASH"
args[1] = key
for i, member := range members {
args[2+i] = member
}
cmd := NewStringSliceCmd(args...)
c.Process(cmd)
return cmd
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zzcadmin/redis.git
git@gitee.com:zzcadmin/redis.git
zzcadmin
redis
redis
v3.2.16

搜索帮助