本文整理汇总了Golang中github.com/bsm/redeo.Request.Args方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Args方法的具体用法?Golang Request.Args怎么用?Golang Request.Args使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bsm/redeo.Request
的用法示例。
在下文中一共展示了Request.Args方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: cmdMset
// MSET
func (m *Miniredis) cmdMset(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
}
if len(r.Args)%2 != 0 {
setDirty(r.Client())
// non-default error message
out.WriteErrorString("ERR wrong number of arguments for MSET")
return nil
}
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
for len(r.Args) > 0 {
key := r.Args[0]
value := r.Args[1]
r.Args = r.Args[2:]
db.del(key, true) // clear TTL
db.stringSet(key, value)
}
out.WriteOK()
})
}
示例2: cmdMsetnx
// MSETNX
func (m *Miniredis) cmdMsetnx(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
}
if len(r.Args)%2 != 0 {
setDirty(r.Client())
// non-default error message (yes, with 'MSET').
out.WriteErrorString("ERR wrong number of arguments for MSET")
return nil
}
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
keys := map[string]string{}
existing := false
for len(r.Args) > 0 {
key := r.Args[0]
value := r.Args[1]
r.Args = r.Args[2:]
keys[key] = value
if _, ok := db.keys[key]; ok {
existing = true
}
}
res := 0
if !existing {
res = 1
for k, v := range keys {
// Nothing to delete. That's the whole point.
db.stringSet(k, v)
}
}
out.WriteInt(res)
})
}
示例3: cmdSet
// SET
func (m *Miniredis) cmdSet(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
}
var (
nx = false // set iff not exists
xx = false // set iff exists
expire = 0 // For seconds and milliseconds.
)
key := r.Args[0]
value := r.Args[1]
r.Args = r.Args[2:]
for len(r.Args) > 0 {
switch strings.ToUpper(r.Args[0]) {
case "NX":
nx = true
r.Args = r.Args[1:]
continue
case "XX":
xx = true
r.Args = r.Args[1:]
continue
case "EX", "PX":
if len(r.Args) < 2 {
setDirty(r.Client())
out.WriteErrorString(msgInvalidInt)
return nil
}
var err error
expire, err = strconv.Atoi(r.Args[1])
if err != nil {
setDirty(r.Client())
out.WriteErrorString(msgInvalidInt)
return nil
}
r.Args = r.Args[2:]
continue
default:
setDirty(r.Client())
out.WriteErrorString(msgSyntaxError)
return nil
}
}
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if nx {
if db.exists(key) {
out.WriteNil()
return
}
}
if xx {
if !db.exists(key) {
out.WriteNil()
return
}
}
db.del(key, true) // be sure to remove existing values of other type keys.
// a vanilla SET clears the expire
db.stringSet(key, value)
if expire != 0 {
db.expire[key] = expire
}
out.WriteOK()
})
}