本文整理汇总了Golang中github.com/mediocregopher/radix/v2/redis.Resp.Array方法的典型用法代码示例。如果您正苦于以下问题:Golang Resp.Array方法的具体用法?Golang Resp.Array怎么用?Golang Resp.Array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/mediocregopher/radix/v2/redis.Resp
的用法示例。
在下文中一共展示了Resp.Array方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseResp
func (c *SubClient) parseResp(resp *redis.Resp) *SubResp {
sr := &SubResp{Resp: resp}
var elems []*redis.Resp
switch {
case resp.IsType(redis.Array):
elems, _ = resp.Array()
if len(elems) < 3 {
sr.Err = errors.New("resp is not formatted as a subscription resp")
sr.Type = Error
return sr
}
case resp.IsType(redis.Err):
sr.Err = resp.Err
sr.Type = Error
return sr
default:
sr.Err = errors.New("resp is not formatted as a subscription resp")
sr.Type = Error
return sr
}
rtype, err := elems[0].Str()
if err != nil {
sr.Err = fmt.Errorf("resp type: %s", err)
sr.Type = Error
return sr
}
//first element
switch rtype {
case "subscribe", "psubscribe":
sr.Type = Subscribe
count, err := elems[2].Int()
if err != nil {
sr.Err = fmt.Errorf("subscribe count: %s", err)
sr.Type = Error
} else {
sr.SubCount = int(count)
}
case "unsubscribe", "punsubscribe":
sr.Type = Unsubscribe
count, err := elems[2].Int()
if err != nil {
sr.Err = fmt.Errorf("unsubscribe count: %s", err)
sr.Type = Error
} else {
sr.SubCount = int(count)
}
case "message", "pmessage":
var chanI, msgI int
if rtype == "message" {
chanI, msgI = 1, 2
} else { // "pmessage"
chanI, msgI = 2, 3
pattern, err := elems[1].Str()
if err != nil {
sr.Err = fmt.Errorf("message pattern: %s", err)
sr.Type = Error
return sr
}
sr.Pattern = pattern
}
sr.Type = Message
channel, err := elems[chanI].Str()
if err != nil {
sr.Err = fmt.Errorf("message channel: %s", err)
sr.Type = Error
return sr
}
sr.Channel = channel
msg, err := elems[msgI].Str()
if err != nil {
sr.Err = fmt.Errorf("message msg: %s", err)
sr.Type = Error
} else {
sr.Message = msg
}
default:
sr.Err = errors.New("suscription multiresp has invalid type: " + rtype)
sr.Type = Error
}
return sr
}