Skip to content

Commit 1863d22

Browse files
committed
inttest and fix some returns
1 parent 5056952 commit 1863d22

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

cmd_sorted_set.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,11 @@ func (m *Miniredis) makeCmdZrank(reverse bool) server.Cmd {
838838
}
839839

840840
if !db.exists(key) {
841-
c.WriteNull()
841+
if withScore {
842+
c.WriteLen(-1)
843+
} else {
844+
c.WriteNull()
845+
}
842846
return
843847
}
844848

@@ -853,7 +857,11 @@ func (m *Miniredis) makeCmdZrank(reverse bool) server.Cmd {
853857
}
854858
rank, ok := db.ssetRank(key, member, direction)
855859
if !ok {
856-
c.WriteNull()
860+
if withScore {
861+
c.WriteLen(-1)
862+
} else {
863+
c.WriteNull()
864+
}
857865
return
858866
}
859867

@@ -864,8 +872,6 @@ func (m *Miniredis) makeCmdZrank(reverse bool) server.Cmd {
864872
} else {
865873
c.WriteInt(rank)
866874
}
867-
868-
869875
})
870876
}
871877
}

integration/sorted_set_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ func TestSortedSet(t *testing.T) {
1818
c.Do("ZRANK", "z", "mies")
1919
c.Do("ZRANK", "z", "vuur")
2020
c.Do("ZRANK", "z", "nosuch")
21+
c.Do("ZRANK", "z", "vuur", "WITHSCORE")
2122
c.Do("ZRANK", "nosuch", "nosuch")
23+
c.Do("ZRANK", "z", "nosuch", "WITHSCORE")
24+
c.Do("ZRANK", "nosuch", "nosuch", "WITHSCORE")
2225
c.Do("ZREVRANK", "z", "aap")
2326
c.Do("ZREVRANK", "z", "noot")
2427
c.Do("ZREVRANK", "z", "mies")
2528
c.Do("ZREVRANK", "z", "vuur")
2629
c.Do("ZREVRANK", "z", "nosuch")
2730
c.Do("ZREVRANK", "nosuch", "nosuch")
31+
c.Do("ZREVRANK", "z", "noot", "WITHSCORE")
32+
c.Do("ZREVRANK", "nosuch", "nosuch", "WITHSCORE")
2833

2934
c.Do("ZADD", "zi", "inf", "aap", "-inf", "noot", "+inf", "mies")
3035
c.Do("ZRANK", "zi", "noot")
@@ -70,6 +75,8 @@ func TestSortedSet(t *testing.T) {
7075
c.Error("wrong number", "ZPOPMIN")
7176
c.Error("out of range", "ZPOPMIN", "set", "noint")
7277
c.Error("syntax error", "ZPOPMIN", "set", "1", "toomany")
78+
c.Error("syntax error", "ZRANK", "z", "nosuch", "WITHSCORES")
79+
c.Error("syntax error", "ZREVRANK", "z", "nosuch", "WITHSCORES")
7380

7481
c.Do("RENAME", "z", "z2")
7582
c.Do("EXISTS", "z")

0 commit comments

Comments
 (0)