本文整理汇总了Golang中github.com/bsm/redeo.Responder.WriteErrorString方法的典型用法代码示例。如果您正苦于以下问题:Golang Responder.WriteErrorString方法的具体用法?Golang Responder.WriteErrorString怎么用?Golang Responder.WriteErrorString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bsm/redeo.Responder
的用法示例。
在下文中一共展示了Responder.WriteErrorString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)))
})
}
示例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: cmdHmget
// HMGET
func (m *Miniredis) cmdHmget(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) < 2 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'hmget' command")
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)
}
})
}
示例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: cmdHexists
// HEXISTS
func (m *Miniredis) cmdHexists(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 2 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'hexists' command")
return nil
}
key := r.Args[0]
field := r.Args[1]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
t, ok := db.keys[key]
if !ok {
out.WriteInt(0)
return
}
if t != "hash" {
out.WriteErrorString(msgWrongType)
return
}
if _, ok := db.hashKeys[key][field]; !ok {
out.WriteInt(0)
return
}
out.WriteInt(1)
})
}
示例7: cmdHvals
// HVALS
func (m *Miniredis) cmdHvals(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'hvals' command")
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)
}
})
}
示例8: cmdLpushx
// LPUSHX
func (m *Miniredis) cmdLpushx(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 2 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'lpushx' command")
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.listLpush(key, value)
out.WriteInt(newLen)
})
}
示例9: cmdPsetex
// PSETEX
func (m *Miniredis) cmdPsetex(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]
ttl, err := strconv.Atoi(r.Args[1])
if err != nil {
setDirty(r.Client())
out.WriteErrorString(msgInvalidInt)
return nil
}
value := r.Args[2]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
db.del(key, true) // Clear any existing keys.
db.stringSet(key, value)
db.expire[key] = ttl // We put millisecond keys in with the second keys.
out.WriteOK()
})
}
示例10: cmdSdiff
// SDIFF
func (m *Miniredis) cmdSdiff(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
}
keys := r.Args
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
set, err := db.setDiff(keys)
if err != nil {
out.WriteErrorString(err.Error())
return
}
out.WriteBulkLen(len(set))
for k := range set {
out.WriteString(k)
}
})
}
示例11: cmdLpop
// LPOP
func (m *Miniredis) cmdLpop(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'lpop' command")
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) {
// Non-existing key is fine.
out.WriteNil()
return
}
if db.t(key) != "list" {
out.WriteErrorString(msgWrongType)
return
}
elem := db.listLpop(key)
out.WriteString(elem)
})
}
示例12: cmdScard
// SCARD
func (m *Miniredis) cmdScard(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.WriteZero()
return
}
if db.t(key) != "set" {
out.WriteErrorString(ErrWrongType.Error())
return
}
members := db.setMembers(key)
out.WriteInt(len(members))
})
}
示例13: cmdSunionstore
// SUNIONSTORE
func (m *Miniredis) cmdSunionstore(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
}
dest := r.Args[0]
keys := r.Args[1:]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
set, err := db.setUnion(keys)
if err != nil {
out.WriteErrorString(err.Error())
return
}
db.del(dest, true)
db.setSet(dest, set)
out.WriteInt(len(set))
})
}
示例14: 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...))
})
}
示例15: cmdSrem
// SREM
func (m *Miniredis) cmdSrem(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) < 2 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'srem' command")
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...))
})
}