Skip to content

Commit 8225546

Browse files
committed
fix ZINTERSTORE where target is one of the source sets
1 parent 4923b04 commit 8225546

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

cmd_sorted_set.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,6 @@ func (m *Miniredis) makeCmdZinter(store bool) func(c *server.Peer, cmd string, a
433433

434434
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
435435
db := m.db(ctx.selectedDB)
436-
if opts.Store {
437-
db.del(opts.Destination, true)
438-
}
439436

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

494491
if opts.Store {
495492
// ZINTERSTORE mode
493+
db.del(opts.Destination, true)
496494
db.ssetSet(opts.Destination, sset)
497495
c.WriteInt(len(sset))
498496
return

integration/sorted_set_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,11 @@ func TestZinter(t *testing.T) {
854854
c.Do("ZINTERSTORE", "dest", "2", "q1", "q2")
855855
c.Do("ZRANGE", "dest", "0", "-1", "withscores")
856856

857+
// store into self
858+
c.Do("ZINTERSTORE", "q1", "2", "q1", "q2")
859+
c.Do("ZRANGE", "q1", "0", "-1", "withscores")
860+
c.Do("SMEMBERS", "q2")
861+
857862
// Error cases
858863
c.Error("wrong number", "ZINTERSTORE")
859864
c.Error("wrong number", "ZINTERSTORE", "h")

0 commit comments

Comments
 (0)