Пример #1
0
func (r *RedisType) GetRedisReplyArray(answer interface{}, err error) []string {
	var reply []string
	res, err2 := redis.Values(answer, err)
	if err2 != nil {
		fmt.Println(err2)
		return reply
	}
	for _, x := range res {
		var v, ok = x.([]byte)
		if ok {
			reply = append(reply, string(v))
		}
		if x == nil {
			reply = append(reply, "false")
		}
	}
	return reply
}
Пример #2
0
func (r *RedisType) GetRedisReply(answer interface{}, err error, names []string) map[string]interface{} {
	var reply []string
	res, _ := redis.Values(answer, err)
	for _, x := range res {
		var v, ok = x.([]byte)
		if ok {
			reply = append(reply, string(v))
		}
		if x == nil {
			reply = append(reply, "false")
		}
	}
	var resp = make(map[string]interface{})
	if len(names) > 0 {
		for i := 0; i < len(reply); i++ {
			resp[names[i]] = reply[i]
		}
	} else {
		for i := 0; i < len(reply); i += 2 {
			resp[reply[i]] = reply[i+1]
		}
	}
	return resp
}