本文整理汇总了Golang中github.com/bsm/redeo.Request.Client方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Client方法的具体用法?Golang Request.Client怎么用?Golang Request.Client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bsm/redeo.Request
的用法示例。
在下文中一共展示了Request.Client方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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))
})
}
示例2: cmdRpop
// RPOP
func (m *Miniredis) cmdRpop(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.WriteNil()
return
}
if db.t(key) != "list" {
out.WriteErrorString(msgWrongType)
return
}
elem := db.listPop(key)
out.WriteString(elem)
})
}
示例3: 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)
})
}
示例4: 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))
})
}
示例5: cmdHmset
// MMSET
func (m *Miniredis) cmdHmset(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) < 3 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'hmset' command")
return nil
}
key := r.Args[0]
args := r.Args[1:]
if len(args)%2 != 0 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for HMSET")
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
}
for len(args) > 0 {
field := args[0]
value := args[1]
args = args[2:]
db.hashSet(key, field, value)
}
out.WriteOK()
})
}
示例6: 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)
}
})
}
示例7: 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()
}
})
}
示例8: 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)
}
})
}
示例9: cmdDecr
// DECR
func (m *Miniredis) cmdDecr(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 t, ok := db.keys[key]; ok && t != "string" {
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)
})
}
示例10: cmdPing
// PING
func (m *Redico) cmdPing(out *redeo.Responder, r *redeo.Request) error {
if !m.handleAuth(r.Client(), out) {
return nil
}
out.WriteInlineString("PONG")
return nil
}
示例11: cmdGetset
// GETSET
func (m *Miniredis) cmdGetset(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
}
old, ok := db.stringKeys[key]
db.stringSet(key, value)
// a GETSET clears the expire
delete(db.expire, key)
if !ok {
out.WriteNil()
return
}
out.WriteString(old)
return
})
}
示例12: 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)
})
}
示例13: 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)
})
}
示例14: 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)
}
})
}
示例15: 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))
})
}