Exemple #1
0
func (r *RedisType) Migrate(host string, port int, key string, db, timeout int, copy, replace bool) (string, error) {
	params := []interface{}{
		host, port, key, db, timeout, copy, replace,
	}
	row, err := redis.String(r.RedisConn.Do("MIGRATE", params...))
	return row, err
}
Exemple #2
0
func (r *RedisType) SPop(key string) (string, error) {
	row, err := redis.String(r.RedisConn.Do("SPOP", key))
	if err == redis.ErrNil {
		return "", nil
	}
	return row, err
}
Exemple #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
	}
}
Exemple #4
0
//PFMERGE destkey sourcekey
func (r *RedisType) Pfadd(destkey string, sourcekey ...string) (string, error) {
	params := make([]interface{}, 0)
	params = append(params, destkey)
	for _, v := range sourcekey {
		params = append(params, v)
	}
	row, err := redis.String(r.RedisConn.Do("PFMERGE", params))
	return row, err
}
Exemple #5
0
func (r *RedisType) Info() (map[string]interface{}, error) {
	row, err := r.RedisConn.Do("INFO")
	if err != nil {
		return nil, err
	}
	row2, err2 := redis.String(row, err)
	info_strings := strings.Split(row2, "\r\n")
	data := make(map[string]interface{})
	title := ""
	pak := make(map[string]interface{})
	for _, values := range info_strings {
		if strings.Count(values, "#") != 0 {
			if title != "" {
				data[title] = pak
			}
			title = values
			pak = make(map[string]interface{})
			continue
		}
		d := strings.Split(values, ":")
		if len(d) == 1 {
			// Если пустое значение
			continue
		}
		c := strings.Split(d[1], ",")
		if len(c) > 1 {
			data2 := make(map[string]string)
			for _, q := range c {
				w := strings.Split(q, "=")
				data2[w[0]] = w[1]
			}
			pak[d[0]] = data2

		} else {
			pak[d[0]] = d[1]
		}
	}
	data[title] = pak
	return data, err2
}
Exemple #6
0
func (r *RedisType) Dump(key string) (string, error) {
	row, err := redis.String(r.RedisConn.Do("DUMP", key))
	return row, err
}
Exemple #7
0
func (r *RedisType) Type(key string) (string, error) {
	row, err := redis.String(r.RedisConn.Do("TYPE", key))
	return row, err
}
Exemple #8
0
func (r *RedisType) RandomKey() (string, error) {
	row, err := redis.String(r.RedisConn.Do("RANDOMKEY"))
	return row, err
}
Exemple #9
0
func (r *RedisType) IncrByFloat(key string, increment float32) (string, error) {
	row, err := redis.String(r.RedisConn.Do("INCRBY", key, increment))
	return row, err
}
Exemple #10
0
func (r *RedisType) GetSet(key string, value interface{}) (string, error) {
	row, err := redis.String(r.RedisConn.Do("SETEX", key, value))
	return row, err
}