本文整理汇总了Golang中github.com/bsm/redeo.Request.WrongNumberOfArgs方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.WrongNumberOfArgs方法的具体用法?Golang Request.WrongNumberOfArgs怎么用?Golang Request.WrongNumberOfArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bsm/redeo.Request
的用法示例。
在下文中一共展示了Request.WrongNumberOfArgs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: cmdHkeys
// HKEYS
func (m *Miniredis) cmdHkeys(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if !db.exists(key) {
out.WriteBulkLen(0)
return
}
if db.t(key) != "hash" {
out.WriteErrorString(msgWrongType)
return
}
fields := db.hashFields(key)
out.WriteBulkLen(len(fields))
for _, f := range fields {
out.WriteString(f)
}
})
}
示例2: cmdRpoplpush
// RPOPLPUSH
func (m *Miniredis) cmdRpoplpush(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 2 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
src := r.Args[0]
dst := r.Args[1]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if !db.exists(src) {
out.WriteNil()
return
}
if db.t(src) != "list" || (db.exists(dst) && db.t(dst) != "list") {
out.WriteErrorString(msgWrongType)
return
}
elem := db.listPop(src)
db.listLpush(dst, elem)
out.WriteString(elem)
})
}
示例3: cmdRpushx
// RPUSHX
func (m *Miniredis) cmdRpushx(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 2 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
value := r.Args[1]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if !db.exists(key) {
out.WriteZero()
return
}
if db.t(key) != "list" {
out.WriteErrorString(msgWrongType)
return
}
newLen := db.listPush(key, value)
out.WriteInt(newLen)
})
}
示例4: cmdRenamenx
// RENAMENX
func (m *Miniredis) cmdRenamenx(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 2 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
from := r.Args[0]
to := r.Args[1]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if !db.exists(from) {
out.WriteErrorString(msgKeyNotFound)
return
}
if db.exists(to) {
out.WriteZero()
return
}
db.rename(from, to)
out.WriteOne()
})
}
示例5: cmdLlen
// LLEN
func (m *Miniredis) cmdLlen(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
t, ok := db.keys[key]
if !ok {
// No such key. That's zero length.
out.WriteZero()
return
}
if t != "list" {
out.WriteErrorString(msgWrongType)
return
}
out.WriteInt(len(db.listKeys[key]))
})
}
示例6: cmdAppend
// APPEND
func (m *Miniredis) cmdAppend(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 2 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
value := r.Args[1]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if t, ok := db.keys[key]; ok && t != "string" {
out.WriteErrorString(msgWrongType)
return
}
newValue := db.stringKeys[key] + value
db.stringSet(key, newValue)
out.WriteInt(len(newValue))
})
}
示例7: cmdMove
// MOVE
func (m *Miniredis) cmdMove(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 2 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
targetDB, err := strconv.Atoi(r.Args[1])
if err != nil {
targetDB = 0
}
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
if ctx.selectedDB == targetDB {
out.WriteErrorString("ERR source and destination objects are the same")
return
}
db := m.db(ctx.selectedDB)
targetDB := m.db(targetDB)
if !db.move(key, targetDB) {
out.WriteZero()
return
}
out.WriteOne()
})
}
示例8: cmdZscore
// ZSCORE
func (m *Miniredis) cmdZscore(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 2 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
member := r.Args[1]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if !db.exists(key) {
out.WriteNil()
return
}
if db.t(key) != "zset" {
out.WriteErrorString(ErrWrongType.Error())
return
}
if !db.ssetExists(key, member) {
out.WriteNil()
return
}
out.WriteString(formatFloat(db.ssetScore(key, member)))
})
}
示例9: cmdSrem
// SREM
func (m *Miniredis) cmdSrem(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) < 2 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
fields := r.Args[1:]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if !db.exists(key) {
out.WriteInt(0)
return
}
if db.t(key) != "set" {
out.WriteErrorString(ErrWrongType.Error())
return
}
out.WriteInt(db.setRem(key, fields...))
})
}
示例10: cmdZincrby
// ZINCRBY
func (m *Miniredis) cmdZincrby(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 3 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
delta, err := strconv.ParseFloat(r.Args[1], 64)
if err != nil {
setDirty(r.Client())
out.WriteErrorString(msgInvalidFloat)
return nil
}
member := r.Args[2]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if db.exists(key) && db.t(key) != "zset" {
out.WriteErrorString(msgWrongType)
return
}
newScore := db.ssetIncrby(key, member, delta)
out.WriteString(formatFloat(newScore))
})
}
示例11: cmdZrem
// ZREM
func (m *Miniredis) cmdZrem(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) < 2 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
members := r.Args[1:]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if !db.exists(key) {
out.WriteZero()
return
}
if db.t(key) != "zset" {
out.WriteErrorString(ErrWrongType.Error())
return
}
deleted := 0
for _, member := range members {
if db.ssetRem(key, member) {
deleted++
}
}
out.WriteInt(deleted)
})
}
示例12: cmdHmget
// HMGET
func (m *Miniredis) cmdHmget(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) < 2 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if t, ok := db.keys[key]; ok && t != "hash" {
out.WriteErrorString(msgWrongType)
return
}
f, ok := db.hashKeys[key]
if !ok {
f = map[string]string{}
}
out.WriteBulkLen(len(r.Args) - 1)
for _, k := range r.Args[1:] {
v, ok := f[k]
if !ok {
out.WriteNil()
continue
}
out.WriteString(v)
}
})
}
示例13: cmdHvals
// HVALS
func (m *Miniredis) cmdHvals(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
t, ok := db.keys[key]
if !ok {
out.WriteBulkLen(0)
return
}
if t != "hash" {
out.WriteErrorString(msgWrongType)
return
}
out.WriteBulkLen(len(db.hashKeys[key]))
for _, v := range db.hashKeys[key] {
out.WriteString(v)
}
})
}
示例14: cmdHset
// HSET
func (m *Miniredis) cmdHset(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 3 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
var (
key = r.Args[0]
field = r.Args[1]
value = r.Args[2]
)
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if t, ok := db.keys[key]; ok && t != "hash" {
out.WriteErrorString(msgWrongType)
return
}
if db.hashSet(key, field, value) {
out.WriteZero()
} else {
out.WriteOne()
}
})
}
示例15: cmdMget
// MGET
func (m *Miniredis) cmdMget(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) < 1 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
out.WriteBulkLen(len(r.Args))
for _, k := range r.Args {
if t, ok := db.keys[k]; !ok || t != "string" {
out.WriteNil()
continue
}
v, ok := db.stringKeys[k]
if !ok {
// Should not happen, we just checked keys[]
out.WriteNil()
continue
}
out.WriteString(v)
}
})
}