Skip to content

Commit

Permalink
inttest and fix some returns
Browse files Browse the repository at this point in the history
  • Loading branch information
alicebob committed Nov 27, 2024
1 parent 5056952 commit 1863d22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cmd_sorted_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,11 @@ func (m *Miniredis) makeCmdZrank(reverse bool) server.Cmd {
}

if !db.exists(key) {
c.WriteNull()
if withScore {
c.WriteLen(-1)
} else {
c.WriteNull()
}
return
}

Expand All @@ -853,7 +857,11 @@ func (m *Miniredis) makeCmdZrank(reverse bool) server.Cmd {
}
rank, ok := db.ssetRank(key, member, direction)
if !ok {
c.WriteNull()
if withScore {
c.WriteLen(-1)
} else {
c.WriteNull()
}
return
}

Expand All @@ -864,8 +872,6 @@ func (m *Miniredis) makeCmdZrank(reverse bool) server.Cmd {
} else {
c.WriteInt(rank)
}


})
}
}
Expand Down
7 changes: 7 additions & 0 deletions integration/sorted_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ func TestSortedSet(t *testing.T) {
c.Do("ZRANK", "z", "mies")
c.Do("ZRANK", "z", "vuur")
c.Do("ZRANK", "z", "nosuch")
c.Do("ZRANK", "z", "vuur", "WITHSCORE")
c.Do("ZRANK", "nosuch", "nosuch")
c.Do("ZRANK", "z", "nosuch", "WITHSCORE")
c.Do("ZRANK", "nosuch", "nosuch", "WITHSCORE")
c.Do("ZREVRANK", "z", "aap")
c.Do("ZREVRANK", "z", "noot")
c.Do("ZREVRANK", "z", "mies")
c.Do("ZREVRANK", "z", "vuur")
c.Do("ZREVRANK", "z", "nosuch")
c.Do("ZREVRANK", "nosuch", "nosuch")
c.Do("ZREVRANK", "z", "noot", "WITHSCORE")
c.Do("ZREVRANK", "nosuch", "nosuch", "WITHSCORE")

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

c.Do("RENAME", "z", "z2")
c.Do("EXISTS", "z")
Expand Down

0 comments on commit 1863d22

Please sign in to comment.