本文整理汇总了Golang中github.com/bsm/redeo.Responder.WriteOne方法的典型用法代码示例。如果您正苦于以下问题:Golang Responder.WriteOne方法的具体用法?Golang Responder.WriteOne怎么用?Golang Responder.WriteOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bsm/redeo.Responder
的用法示例。
在下文中一共展示了Responder.WriteOne方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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()
}
})
}
示例2: 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()
})
}
示例3: cmdRenamenx
// RENAMENX
func (m *Miniredis) cmdRenamenx(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
}
from := r.Args[0]
to := r.Args[1]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if !db.exists(from) {
out.WriteErrorString(msgKeyNotFound)
return
}
if db.exists(to) {
out.WriteZero()
return
}
db.rename(from, to)
out.WriteOne()
})
}
示例4: 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()
})
}
示例5: cmdMove
// MOVE
func (m *Miniredis) cmdMove(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]
targetDB, err := strconv.Atoi(r.Args[1])
if err != nil {
targetDB = 0
}
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
if ctx.selectedDB == targetDB {
out.WriteErrorString("ERR source and destination objects are the same")
return
}
db := m.db(ctx.selectedDB)
targetDB := m.db(targetDB)
if !db.move(key, targetDB) {
out.WriteZero()
return
}
out.WriteOne()
})
}
示例6: cmdSismember
// SISMEMBER
func (m *Miniredis) cmdSismember(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) != "set" {
out.WriteErrorString(ErrWrongType.Error())
return
}
if db.setIsMember(key, value) {
out.WriteOne()
return
}
out.WriteZero()
})
}
示例7: cmdHset
// HSET
func (m *Miniredis) cmdHset(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
}
var (
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: cmdSetnx
// SETNX
func (m *Miniredis) cmdSetnx(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 _, ok := db.keys[key]; ok {
out.WriteZero()
return
}
db.stringSet(key, value)
out.WriteOne()
})
}
示例9: cmdHsetnx
// HSETNX
func (m *Miniredis) cmdHsetnx(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
}
var (
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()
})
}