Example #1
0
func (r *RedisType) SMembers(key string) ([]string, error) {
	row, err := redis.Strings(r.RedisConn.Do("SMEMBERS", key))
	if err == redis.ErrNil {
		return nil, nil
	}
	return row, err
}
Example #2
0
func (r *RedisType) MGet(keys []string) ([]string, error) {
	params := make([]interface{}, 0)
	for _, v := range keys {
		params = append(params, v)
	}
	row, err := redis.Strings(r.RedisConn.Do("MGET", params...))
	return row, err
}
Example #3
0
func (r *RedisType) SRandMember(key string, count ...int) (interface{}, error) {
	if len(count) > 0 {
		row, err := redis.Strings(r.RedisConn.Do("SRANDMEMBER", key, count[0]))
		return row, err
	} else {
		row, err := redis.String(r.RedisConn.Do("SRANDMEMBER", key))
		return row, err
	}
}
Example #4
0
//ZRANGEBYLEX key min max [LIMIT offset count
func (r *RedisType) ZRangeByLex(key string, min, max int, other ...interface{}) (interface{}, error) {
	params := make([]interface{}, 0)
	params = append(params, key)
	params = append(params, min)
	params = append(params, max)
	if len(other) > 0 && len(other) == 3 {
		for _, v := range other {
			params = append(params, v)
		}
	}
	row, err := redis.Strings(r.RedisConn.Do("ZRANGEBYLEX", params...))
	if err == redis.ErrNil {
		return nil, nil
	}
	return row, err
}
Example #5
0
func (r *RedisType) ZRevRangeByScore(key string, min, max int, withScore bool) (interface{}, error) {
	row, err := redis.Strings(r.RedisConn.Do("ZREVRANGEBYSCORE", key, min, max))
	if err == redis.ErrNil {
		return nil, nil
	}
	if withScore {
		data := make(map[string]interface{})
		for _, key2 := range row {
			row2, err2 := r.ZScore(key, key2)
			if err2 != nil {
				data[key2] = nil
				continue
			} else {
				data[key2] = row2
			}
		}
		return data, nil
	}
	return row, err
}
Example #6
0
func (r *RedisType) ZRange(key string, start, stop int, withScore bool) (interface{}, error) {
	params := make([]interface{}, 0)
	params = append(params, key)
	params = append(params, start)
	params = append(params, stop)
	row, err := redis.Strings(r.RedisConn.Do("ZRANGE", params...))
	if err == redis.ErrNil {
		return nil, nil
	}
	if withScore {
		data := make(map[string]interface{})
		for _, key2 := range row {
			row2, err2 := r.ZScore(key, key2)
			if err2 != nil {
				data[key2] = nil
				continue
			} else {
				data[key2] = row2
			}
		}
		return data, nil
	}
	return row, err
}
Example #7
0
func (r *RedisType) Keys(pattern string) ([]string, error) {
	row, err := redis.Strings(r.RedisConn.Do("KEYS", pattern))
	return row, err
}