本文整理汇总了Golang中github.com/bsm/redeo.Responder.WriteInt方法的典型用法代码示例。如果您正苦于以下问题:Golang Responder.WriteInt方法的具体用法?Golang Responder.WriteInt怎么用?Golang Responder.WriteInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bsm/redeo.Responder
的用法示例。
在下文中一共展示了Responder.WriteInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: cmdDecrby
// DECRBY
func (m *Miniredis) cmdDecrby(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]
delta, err := strconv.Atoi(r.Args[1])
if err != nil {
setDirty(r.Client())
out.WriteErrorString(msgInvalidInt)
return nil
}
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
}
v, err := db.stringIncr(key, -delta)
if err != nil {
out.WriteErrorString(err.Error())
return
}
// Don't touch TTL
out.WriteInt(v)
})
}
示例2: 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)
})
}
示例3: 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)
})
}
示例4: cmdScard
// SCARD
func (m *Miniredis) cmdScard(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'scard' 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) {
out.WriteZero()
return
}
if db.t(key) != "set" {
out.WriteErrorString(ErrWrongType.Error())
return
}
members := db.setMembers(key)
out.WriteInt(len(members))
})
}
示例5: cmdHincrby
// HINCRBY
func (m *Miniredis) cmdHincrby(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 3 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'hincrby' command")
return nil
}
key := r.Args[0]
field := r.Args[1]
delta, err := strconv.Atoi(r.Args[2])
if err != nil {
setDirty(r.Client())
out.WriteErrorString(msgInvalidInt)
return nil
}
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
}
v, err := db.hashIncr(key, field, delta)
if err != nil {
out.WriteErrorString(err.Error())
return
}
out.WriteInt(v)
})
}
示例6: cmdLinsert
// LINSERT
func (m *Miniredis) cmdLinsert(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 4 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
where := 0
switch strings.ToLower(r.Args[1]) {
case "before":
where = -1
case "after":
where = +1
default:
setDirty(r.Client())
out.WriteErrorString(msgSyntaxError)
return nil
}
pivot := r.Args[2]
value := r.Args[3]
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
out.WriteZero()
return
}
if t != "list" {
out.WriteErrorString(msgWrongType)
return
}
l := db.listKeys[key]
for i, el := range l {
if el != pivot {
continue
}
if where < 0 {
l = append(l[:i], append(listKey{value}, l[i:]...)...)
} else {
if i == len(l)-1 {
l = append(l, value)
} else {
l = append(l[:i+1], append(listKey{value}, l[i+1:]...)...)
}
}
db.listKeys[key] = l
db.keyVersion[key]++
out.WriteInt(len(l))
return
}
out.WriteInt(-1)
})
}
示例7: 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)
})
}
示例8: 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...))
})
}
示例9: cmdRpush
// RPUSH
func (m *Miniredis) cmdRpush(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]
args := r.Args[1:]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if db.exists(key) && db.t(key) != "list" {
out.WriteErrorString(msgWrongType)
return
}
var newLen int
for _, value := range args {
newLen = db.listPush(key, value)
}
out.WriteInt(newLen)
})
}
示例10: 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))
})
}
示例11: cmdIncr
// INCR
func (m *Redico) cmdIncr(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)
key := r.Args[0]
if !db.exists(key) {
out.WriteErrorString(msgWrongType)
return
}
v, err := db.stringIncr(key, +1)
if err != nil {
out.WriteErrorString(err.Error())
return
}
// Don't touch TTL
out.WriteInt(v)
})
}
示例12: 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))
})
}
示例13: 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...))
})
}
示例14: 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]))
})
}
示例15: 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))
})
}