Ejemplo n.º 1
0
//
// Return the bool in the Redis Reply
//
// Redis/Casting Error --> error
// Nil Reply           --> false
// All other cases     --> true or false
//
func ReplyToBool(reply *redis.Reply) (bool, error) {
	switch {
	case nil != reply.Err:
		return false, reply.Err
	case redis.NilReply == reply.Type:
		return false, nil
	default:
		return reply.Bool()
	}
}
Ejemplo n.º 2
0
//
// Return the float64 pointer in the Redis Reply
//
// Redis/Casting Error --> error
// Cache Miss          --> nil ptr
// Cache Hit           --> valid ptr
//
func ReplyToFloat64Ptr(reply *redis.Reply) (*float64, error) {
	switch {
	case nil != reply.Err:
		return nil, reply.Err
	case redis.NilReply == reply.Type:
		return nil, nil
	default:
		value, err := reply.Float64()
		if nil != err {
			return nil, err
		}
		return &value, nil
	}
}
Ejemplo n.º 3
0
//
// Return the string pointer in the Redis Reply
//
// Redis/Casting Error --> error
// Cache Miss          --> nil ptr
// Cache Hit           --> valid ptr
//
func ReplyToStringPtr(reply *redis.Reply) (*string, error) {
	switch {
	case nil != reply.Err:
		return nil, reply.Err
	case redis.NilReply == reply.Type:
		return nil, nil
	case redis.IntegerReply == reply.Type:
		i64, err := reply.Int64()
		if nil != err {
			return nil, err
		}
		value := fmt.Sprintf("%d", i64)
		return &value, nil
	default:
		value, err := reply.Str()
		if nil != err {
			return nil, err
		}
		return &value, nil
	}
}
Ejemplo n.º 4
0
func (p *RedisConnection) logReply(cmd, reply_depth string, reply *redis.Reply) {
	if log4go.INFO < minLogLevel(p.Logger) {
		return
	}

	// Log the response
	switch reply.Type {
	case redis.StatusReply:
		b, _ := reply.Bool()
		p.Logger.Info("[RedisConnection][GetReply][%s/%s] Redis Reply[%v], Cmd=%v, Reply.Type=StatusReply, Reply.Status=%v", p.Url, p.Id, reply_depth, cmd, b)
		return

	case redis.ErrorReply:
		p.Logger.Info("[RedisConnection][GetReply][%s/%s] Redis Reply[%v], Cmd=%v, Reply.Type=ErrorReply, Reply.Err=%v", p.Url, p.Id, reply_depth, cmd, reply.Err)
		return

	case redis.IntegerReply:
		i, _ := reply.Int64()
		p.Logger.Info("[RedisConnection][GetReply][%s/%s] Redis Reply[%v], Cmd=%v, Reply.Type=IntegerReply, Reply.Int=%v", p.Url, p.Id, reply_depth, cmd, i)
		return

	case redis.NilReply:
		p.Logger.Info("[RedisConnection][GetReply][%s/%s] Redis Reply[%v], Cmd=%v, Reply.Type=NilReply", p.Url, p.Id, reply_depth, cmd)
		return

	case redis.BulkReply:
		b, _ := reply.Bytes()
		p.Logger.Info("[RedisConnection][GetReply][%s/%s] Redis Reply[%v], Cmd=%v, Reply.Type=BulkReply, Reply.Str=%v, Reply.Bytes=%v", p.Url, p.Id, reply_depth, cmd, string(b), b)
		return

	case redis.MultiReply:
		p.Logger.Info("[RedisConnection][GetReply][%s/%s] Redis Reply[%v], Cmd=%v, Reply.Type=MultiReply, Reply.Elems.Count=%v", p.Url, p.Id, reply_depth, cmd, len(reply.Elems))
		for i, elem := range reply.Elems {
			p.logReply(cmd, fmt.Sprintf("%s->%d", reply_depth, i), elem)
		}
		return

	default:
		p.Logger.Info("[RedisConnection][GetReply][%s/%s] Redis Reply[%v], Cmd=%v, Reply=%#v", p.Url, p.Id, reply_depth, cmd, reply)
		return
	}
}