本文整理汇总了Golang中github.com/bsm/redeo.Responder.WriteOK方法的典型用法代码示例。如果您正苦于以下问题:Golang Responder.WriteOK方法的具体用法?Golang Responder.WriteOK怎么用?Golang Responder.WriteOK使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bsm/redeo.Responder
的用法示例。
在下文中一共展示了Responder.WriteOK方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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()
})
}
示例2: 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()
})
}
示例3: 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()
})
}
示例4: cmdFlushall
// FLUSHALL
func (m *Miniredis) cmdFlushall(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) > 0 {
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) {
m.dbs = map[int]*RedisDB{}
out.WriteOK()
})
}
示例5: cmdFlushdb
// FLUSHDB
func (m *Miniredis) cmdFlushdb(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) > 0 {
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) {
delete(m.dbs, ctx.selectedDB)
out.WriteOK()
})
}
示例6: cmdUnwatch
// UNWATCH
func (m *Miniredis) cmdUnwatch(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 0 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'unwatch' command")
return nil
}
// Doesn't matter if UNWATCH is in a TX or not. Looks like a Redis bug to me.
unwatch(getCtx(r.Client()))
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
// Do nothing if it's called in a transaction.
out.WriteOK()
})
}
示例7: cmdMulti
// MULTI
func (m *Miniredis) cmdMulti(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 0 {
out.WriteErrorString("ERR wrong number of arguments for 'multi' command")
return nil
}
ctx := getCtx(r.Client())
if inTx(ctx) {
out.WriteErrorString("ERR MULTI calls can not be nested")
return nil
}
startTx(ctx)
out.WriteOK()
return nil
}
示例8: cmdDiscard
// DISCARD
func (m *Miniredis) cmdDiscard(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 0 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'discard' command")
return nil
}
ctx := getCtx(r.Client())
if !inTx(ctx) {
out.WriteErrorString("ERR DISCARD without MULTI")
return nil
}
stopTx(ctx)
out.WriteOK()
return nil
}
示例9: cmdUnwatch
// UNWATCH
func (m *Miniredis) cmdUnwatch(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 0 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
// Doesn't matter if UNWATCH is in a TX or not. Looks like a Redis bug to me.
unwatch(getCtx(r.Client()))
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
// Do nothing if it's called in a transaction.
out.WriteOK()
})
}
示例10: cmdDiscard
// DISCARD
func (m *Miniredis) cmdDiscard(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 0 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
ctx := getCtx(r.Client())
if !inTx(ctx) {
return redeo.ClientError("DISCARD without MULTI")
}
stopTx(ctx)
out.WriteOK()
return nil
}
示例11: cmdMulti
// MULTI
func (m *Miniredis) cmdMulti(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 0 {
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
ctx := getCtx(r.Client())
if inTx(ctx) {
return redeo.ClientError("MULTI calls can not be nested")
}
startTx(ctx)
out.WriteOK()
return nil
}
示例12: cmdLset
// LSET
func (m *Miniredis) cmdLset(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]
index, 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)
if !db.exists(key) {
out.WriteErrorString(msgKeyNotFound)
return
}
if db.t(key) != "list" {
out.WriteErrorString(msgWrongType)
return
}
l := db.listKeys[key]
if index < 0 {
index = len(l) + index
}
if index < 0 || index > len(l)-1 {
out.WriteErrorString(msgOutOfRange)
return
}
l[index] = value
db.keyVersion[key]++
out.WriteOK()
})
}
示例13: cmdLtrim
// LTRIM
func (m *Miniredis) cmdLtrim(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)
t, ok := db.keys[key]
if !ok {
out.WriteOK()
return
}
if t != "list" {
out.WriteErrorString(msgWrongType)
return
}
l := db.listKeys[key]
rs, re := redisRange(len(l), start, end, false)
db.listKeys[key] = l[rs:re]
db.keyVersion[key]++
out.WriteOK()
})
}
示例14: cmdSelect
// SELECT
func (m *Miniredis) cmdSelect(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
out.WriteErrorString("usage error")
return nil
}
id, err := strconv.Atoi(r.Args[0])
if err != nil {
id = 0
}
m.Lock()
defer m.Unlock()
ctx := getCtx(r.Client())
ctx.selectedDB = id
out.WriteOK()
return nil
}
示例15: cmdAuth
// AUTH
func (m *Redico) cmdAuth(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
pw := r.Args[0]
m.Lock()
defer m.Unlock()
if m.password == "" {
out.WriteErrorString("ERR Client sent AUTH, but no password is set")
return nil
}
if m.password != pw {
out.WriteErrorString("ERR invalid password")
return nil
}
setAuthenticated(r.Client())
out.WriteOK()
return nil
}