本文整理汇总了Golang中github.com/bsm/redeo.Request类的典型用法代码示例。如果您正苦于以下问题:Golang Request类的具体用法?Golang Request怎么用?Golang Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: cmdZscore
// ZSCORE
func (m *Miniredis) cmdZscore(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 2 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'zscore' command")
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: cmdGetrange
// GETRANGE
func (m *Miniredis) cmdGetrange(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]
start, err := strconv.Atoi(r.Args[1])
if err != nil {
setDirty(r.Client())
out.WriteErrorString(msgInvalidInt)
return nil
}
end, 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 != "string" {
out.WriteErrorString(msgWrongType)
return
}
v := db.stringKeys[key]
out.WriteString(withRange(v, start, end))
})
}
示例3: cmdZincrby
// ZINCRBY
func (m *Miniredis) cmdZincrby(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 3 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'zincrby' command")
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))
})
}
示例4: 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)
})
}
示例5: cmdLlen
// LLEN
func (m *Miniredis) cmdLlen(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'llen' 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 {
// No such key. That's zero length.
out.WriteZero()
return
}
if t != "list" {
out.WriteErrorString(msgWrongType)
return
}
out.WriteInt(len(db.listKeys[key]))
})
}
示例6: cmdHsetnx
// HSETNX
func (m *Miniredis) cmdHsetnx(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 3 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'hsetnx' command")
return nil
}
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 _, ok := db.hashKeys[key]; !ok {
db.hashKeys[key] = map[string]string{}
db.keys[key] = "hash"
}
_, ok := db.hashKeys[key][field]
if ok {
out.WriteZero()
return
}
db.hashKeys[key][field] = value
db.keyVersion[key]++
out.WriteOne()
})
}
示例7: cmdHkeys
// HKEYS
func (m *Miniredis) cmdHkeys(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'hkeys' 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.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)
}
})
}
示例8: 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))
})
}
示例9: 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)
})
}
示例10: cmdSismember
// SISMEMBER
func (m *Miniredis) cmdSismember(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 2 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'sismember' 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) != "set" {
out.WriteErrorString(ErrWrongType.Error())
return
}
if db.setIsMember(key, value) {
out.WriteOne()
return
}
out.WriteZero()
})
}
示例11: 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...))
})
}
示例12: 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)
}
})
}
示例13: cmdHset
// HSET
func (m *Miniredis) cmdHset(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 3 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'hset' command")
return nil
}
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()
}
})
}
示例14: cmdHincrbyfloat
// HINCRBYFLOAT
func (m *Miniredis) cmdHincrbyfloat(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 3 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'hincrbyfloat' command")
return nil
}
key := r.Args[0]
field := r.Args[1]
delta, err := strconv.ParseFloat(r.Args[2], 64)
if err != nil {
setDirty(r.Client())
out.WriteErrorString(msgInvalidFloat)
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.hashIncrfloat(key, field, delta)
if err != nil {
out.WriteErrorString(err.Error())
return
}
out.WriteString(formatFloat(v))
})
}
示例15: cmdZrem
// ZREM
func (m *Miniredis) cmdZrem(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) < 2 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'zrem' command")
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)
})
}