Skip to content

Commit

Permalink
fix ZINTERSTORE where target is one of the source sets
Browse files Browse the repository at this point in the history
  • Loading branch information
alicebob committed Jul 24, 2024
1 parent 4923b04 commit 8225546
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 1 addition & 3 deletions cmd_sorted_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,6 @@ func (m *Miniredis) makeCmdZinter(store bool) func(c *server.Peer, cmd string, a

withTx(m, c, func(c *server.Peer, ctx *connCtx) {
db := m.db(ctx.selectedDB)
if opts.Store {
db.del(opts.Destination, true)
}

// We collect everything and remove all keys which turned out not to be
// present in every set.
Expand Down Expand Up @@ -493,6 +490,7 @@ func (m *Miniredis) makeCmdZinter(store bool) func(c *server.Peer, cmd string, a

if opts.Store {
// ZINTERSTORE mode
db.del(opts.Destination, true)
db.ssetSet(opts.Destination, sset)
c.WriteInt(len(sset))
return
Expand Down
5 changes: 5 additions & 0 deletions integration/sorted_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,11 @@ func TestZinter(t *testing.T) {
c.Do("ZINTERSTORE", "dest", "2", "q1", "q2")
c.Do("ZRANGE", "dest", "0", "-1", "withscores")

// store into self
c.Do("ZINTERSTORE", "q1", "2", "q1", "q2")
c.Do("ZRANGE", "q1", "0", "-1", "withscores")
c.Do("SMEMBERS", "q2")

// Error cases
c.Error("wrong number", "ZINTERSTORE")
c.Error("wrong number", "ZINTERSTORE", "h")
Expand Down

0 comments on commit 8225546

Please sign in to comment.