本文整理汇总了Golang中github.com/bsm/redeo.Responder类的典型用法代码示例。如果您正苦于以下问题:Golang Responder类的具体用法?Golang Responder怎么用?Golang Responder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Responder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: cmdSmembers
// SMEMBERS
func (m *Miniredis) cmdSmembers(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'smembers' 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) != "set" {
out.WriteErrorString(ErrWrongType.Error())
return
}
members := db.setMembers(key)
out.WriteBulkLen(len(members))
for _, elem := range members {
out.WriteString(elem)
}
})
}
开发者ID:jameswei,项目名称:xcodis,代码行数:31,代码来源:cmd_set.go
示例2: 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)))
})
}
开发者ID:jameswei,项目名称:xcodis,代码行数:32,代码来源:cmd_sorted_set.go
示例3: 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)
})
}
开发者ID:jameswei,项目名称:xcodis,代码行数:30,代码来源:cmd_hash.go
示例4: cmdSunionstore
// SUNIONSTORE
func (m *Miniredis) cmdSunionstore(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
}
dest := r.Args[0]
keys := r.Args[1:]
return withTx(m, out, r, func(out *redeo.Responder, ctx *connCtx) {
db := m.db(ctx.selectedDB)
set, err := db.setUnion(keys)
if err != nil {
out.WriteErrorString(err.Error())
return
}
db.del(dest, true)
db.setSet(dest, set)
out.WriteInt(len(set))
})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:27,代码来源:cmd_set.go
示例5: cmdHvals
// HVALS
func (m *Miniredis) cmdHvals(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'hvals' 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 {
out.WriteBulkLen(0)
return
}
if t != "hash" {
out.WriteErrorString(msgWrongType)
return
}
out.WriteBulkLen(len(db.hashKeys[key]))
for _, v := range db.hashKeys[key] {
out.WriteString(v)
}
})
}
开发者ID:jameswei,项目名称:xcodis,代码行数:28,代码来源:cmd_hash.go
示例6: 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()
})
}
开发者ID:jameswei,项目名称:xcodis,代码行数:31,代码来源:cmd_set.go
示例7: 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)
}
})
}
开发者ID:jameswei,项目名称:xcodis,代码行数:33,代码来源:cmd_hash.go
示例8: 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))
})
}
开发者ID:jameswei,项目名称:xcodis,代码行数:32,代码来源:cmd_hash.go
示例9: cmdRandomkey
// RANDOMKEY
func (m *Miniredis) cmdRandomkey(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) {
db := m.db(ctx.selectedDB)
if len(db.keys) == 0 {
out.WriteNil()
return
}
nr := rand.Intn(len(db.keys))
for k := range db.keys {
if nr == 0 {
out.WriteString(k)
return
}
nr--
}
})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:27,代码来源:cmd_generic.go
示例10: cmdAppend
// APPEND
func (m *Miniredis) cmdAppend(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
}
newValue := db.stringKeys[key] + value
db.stringSet(key, newValue)
out.WriteInt(len(newValue))
})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:27,代码来源:cmd_string.go
示例11: 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)
})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:27,代码来源:cmd_list.go
示例12: 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()
})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:27,代码来源:cmd_string.go
示例13: 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()
})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:29,代码来源:cmd_string.go
示例14: cmdLinsert
// LINSERT
func (m *Miniredis) cmdLinsert(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 4 {
setDirty(r.Client())
return r.WrongNumberOfArgs()
}
if !m.handleAuth(r.Client(), out) {
return nil
}
key := r.Args[0]
where := 0
switch strings.ToLower(r.Args[1]) {
case "before":
where = -1
case "after":
where = +1
default:
setDirty(r.Client())
out.WriteErrorString(msgSyntaxError)
return nil
}
pivot := r.Args[2]
value := r.Args[3]
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
out.WriteZero()
return
}
if t != "list" {
out.WriteErrorString(msgWrongType)
return
}
l := db.listKeys[key]
for i, el := range l {
if el != pivot {
continue
}
if where < 0 {
l = append(l[:i], append(listKey{value}, l[i:]...)...)
} else {
if i == len(l)-1 {
l = append(l, value)
} else {
l = append(l[:i+1], append(listKey{value}, l[i+1:]...)...)
}
}
db.listKeys[key] = l
db.keyVersion[key]++
out.WriteInt(len(l))
return
}
out.WriteInt(-1)
})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:61,代码来源:cmd_list.go
示例15: 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
}
开发者ID:yqj2012,项目名称:Coolpy5Sub,代码行数:8,代码来源:cmd_connnection.go
示例16: 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)
}
})
}
开发者ID:jameswei,项目名称:xcodis,代码行数:28,代码来源:cmd_hash.go
示例17: cmdHgetall
// HGETALL
func (m *Miniredis) cmdHgetall(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)
t, ok := db.keys[key]
if !ok {
out.WriteBulkLen(0)
return
}
if t != "hash" {
out.WriteErrorString(msgWrongType)
return
}
out.WriteBulkLen(len(db.hashKeys[key]) * 2)
for _, k := range db.hashFields(key) {
out.WriteString(k)
out.WriteString(db.hashGet(key, k))
}
})
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:32,代码来源:cmd_hash.go
示例18: cmdLrem
// LREM
func (m *Miniredis) cmdLrem(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 3 {
setDirty(r.Client())
out.WriteErrorString("ERR wrong number of arguments for 'lrem' command")
return nil
}
key := r.Args[0]
count, 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.WriteZero()
return
}
if db.t(key) != "list" {
out.WriteErrorString(msgWrongType)
return
}
l := db.listKeys[key]
if count < 0 {
reverseSlice(l)
}
deleted := 0
newL := []string{}
toDelete := len(l)
if count < 0 {
toDelete = -count
}
if count > 0 {
toDelete = count
}
for _, el := range l {
if el == value {
if toDelete > 0 {
deleted++
toDelete--
continue
}
}
newL = append(newL, el)
}
if count < 0 {
reverseSlice(newL)
}
db.listKeys[key] = newL
db.keyVersion[key]++
out.WriteInt(deleted)
})
}
开发者ID:jameswei,项目名称:xcodis,代码行数:60,代码来源:cmd_list.go
示例19: cmdEcho
// ECHO
func (m *Miniredis) cmdEcho(out *redeo.Responder, r *redeo.Request) error {
if len(r.Args) != 1 {
setDirty(r.Client())
out.WriteErrorString("usage error")
return nil
}
msg := r.Args[0]
out.WriteString(msg)
return nil
}
开发者ID:jameswei,项目名称:xcodis,代码行数:11,代码来源:cmd_connection.go
示例20: cmdEcho
// ECHO
func (m *Redico) cmdEcho(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
}
msg := r.Args[0]
out.WriteString(msg)
return nil
}
开发者ID:yqj2012,项目名称:Coolpy5Sub,代码行数:13,代码来源:cmd_connnection.go
注:本文中的github.com/bsm/redeo.Responder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论