Skip to content

Commit

Permalink
Merge pull request #3 from liufuqiang/master
Browse files Browse the repository at this point in the history
修改redis 的 Zrange 方法,支持WITHSCORES; 增加Zmadd方法
  • Loading branch information
astaxie committed Jul 7, 2013
2 parents ae106a8 + cba2a06 commit 352f2b4
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,20 @@ func (client *Client) Zmadd(key string, values map[string]float64 ) (bool, error
}


func (client *Client) Zmadd(key string, values map[string]float64 ) (bool, error) {
args := []string{key}
for value,score := range values {
args = append(args, strconv.FormatFloat(score, 'f', -1, 64))
args = append(args, value)
}
res, err := client.sendCommand("ZADD", args...)
if err != nil {
return false, err
}

return res.(int64) >= 1, nil
}

func (client *Client) Zrem(key string, value []byte) (bool, error) {
res, err := client.sendCommand("ZREM", key, string(value))
if err != nil {
Expand Down Expand Up @@ -975,13 +989,17 @@ func (client *Client) Zrevrank(key string, value []byte) (int, error) {
return int(res.(int64)), nil
}

func (client *Client) Zrange(key string, start int, end int) ([][]byte, error) {
res, err := client.sendCommand("ZRANGE", key, strconv.Itoa(start), strconv.Itoa(end))
if err != nil {
return nil, err
}

return res.([][]byte), nil
func (client *Client) Zrange(key string, start int, end int,WITHSCORES ...string) ([][]byte, error) {
args := []string{key,strconv.Itoa(start), strconv.Itoa(end)}
if len(WITHSCORES) == 1 && WITHSCORES[0] == "WITHSCORES" {
args = append(args,"WITHSCORES")
}
res, err := client.sendCommand("ZRANGE", args...)
if err != nil {
return nil, err
}

return res.([][]byte), nil
}

func (client *Client) Zrevrange(key string, start int, end int) ([][]byte, error) {
Expand Down

0 comments on commit 352f2b4

Please sign in to comment.