Example #1
0
func getHash(pool *redis.Pool, id string) map[string]int {
	c := pool.Get()
	defer c.Close()
	m, err := redis.IntMap(c.Do("HGETALL", id))
	utee.Chk(err)
	return m
}
Example #2
0
func TestHalfMonthProcess(t *testing.T) {
	var m common.MetricEntry

	//initial time in seconds for current bucket
	current := begginingOfBucketUnix(time.Now().UTC())

	lastSecondPreviousBucket := time.Unix(current-1, 0)

	//get unixtime start date for the previous finished bucket
	prev := begginingOfBucketUnix(lastSecondPreviousBucket)

	day := time.Unix(prev, 0)

	for i := 0; i < int(bucketLength); i++ {
		m = common.MetricEntry{"John", 1, "call-api-x", &day}
		r.processMetric(m)
		m = common.MetricEntry{"Charles", 1, "login", &day}
		r.processMetric(m)
		day = day.Add(time.Hour * 24)
	}

	dest, err := r.processBuckets()
	resultMap, err := redis.IntMap(r.Do("ZRANGE", dest, 0, -1, "WITHSCORES"))

	assert.Nil(t, err, "must be nil")
	assert.Equal(t, len(resultMap), 2, "must be ...")
	assert.EqualValues(t, resultMap["call-api-x"], bucketLength, "must be ...")
	assert.EqualValues(t, resultMap["login"], bucketLength, "must be ...")

}
Example #3
0
func (c *CacheRedis) GetMap(key string) map[string]int {
	val, err := redis.IntMap(c.conn.Do("HGETALL", key))
	if err != nil {
		panic(err)
		return make(map[string]int)
	}
	return val
}
Example #4
0
func (r *Redis) HasActiveSubscribers(topic string) (bool, error) {
	conn := r.getConn()
	defer conn.Close()

	data, err := redis.IntMap(conn.Do("PUBSUB", "NUMSUB", topic))
	if err == nil {
		count, has := data[topic]
		return has && count > 0, err
	} else {
		return false, err
	}
}
Example #5
0
func (*RedisStore) IntMap(reply interface{}, err error) (map[string]int, error) {
	return redis.IntMap(reply, err)
}