Skip to content

Commit dc3e5ae

Browse files
committed
Fix Zincrby and Zscore
1 parent a65bd67 commit dc3e5ae

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

redis.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ func (client *Client) Zrem(key string, value []byte) (bool, os.Error) {
796796
}
797797

798798
func (client *Client) Zincrby(key string, value []byte, score float64) (float64, os.Error) {
799-
res, err := client.sendCommand("ZINCRBY", []string{key, string(value), strconv.Ftoa64(score, 'f', -1)})
799+
res, err := client.sendCommand("ZINCRBY", []string{key, strconv.Ftoa64(score, 'f', -1), string(value)})
800800
if err != nil {
801801
return 0, err
802802
}
@@ -860,8 +860,8 @@ func (client *Client) Zcard(key string) (int, os.Error) {
860860
return int(res.(int64)), nil
861861
}
862862

863-
func (client *Client) Zscore(key string) (float64, os.Error) {
864-
res, err := client.sendCommand("ZSCORE", []string{key})
863+
func (client *Client) Zscore(key string, member []byte) (float64, os.Error) {
864+
res, err := client.sendCommand("ZSCORE", []string{key, string(member)})
865865
if err != nil {
866866
return 0, err
867867
}

redis_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ func TestSortedSet(t *testing.T) {
222222
if err != nil {
223223
t.Fatal("zdd failed" + err.String())
224224
}
225+
score, err := client.Zscore("zs", vals[i])
226+
if err != nil {
227+
t.Fatal("zscore failed" + err.String())
228+
}
229+
if score != ranks[i] {
230+
t.Fatal("zscore failed")
231+
}
225232
}
226233

227234
card, err := client.Zcard("zs")
@@ -243,6 +250,22 @@ func TestSortedSet(t *testing.T) {
243250
t.Fatal("zrangebyscore failed")
244251
}
245252
}
253+
//incremement
254+
for i := 0; i <= 4; i++ {
255+
client.Zincrby("zs", vals[i], 1)
256+
257+
score, err := client.Zscore("zs", vals[i])
258+
if err != nil {
259+
t.Fatal("zscore failed" + err.String())
260+
}
261+
if score != ranks[i]+1 {
262+
t.Fatal("zscore failed")
263+
}
264+
}
265+
266+
for i := 0; i <= 4; i++ {
267+
client.Zincrby("zs", vals[i], -1)
268+
}
246269

247270
//clean up
248271
_, err = client.Zrem("zs", []byte("a"))

0 commit comments

Comments
 (0)