summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2010-07-06 18:30:38 +0200
committerantirez <antirez@gmail.com>2010-07-06 18:30:38 +0200
commitb056ca39f2d37957164c5bfc04c466b64aa6087e (patch)
treeefb8b8e8a5017b395a7e08f01f533c0632834a24
parent8b654e54c490161983e42a328675e484e404e2d2 (diff)
downloadredis-b056ca39f2d37957164c5bfc04c466b64aa6087e.tar.gz
improved random dataset creation in test: del, sunionstore, zunionstore
-rw-r--r--tests/support/util.tcl32
1 files changed, 30 insertions, 2 deletions
diff --git a/tests/support/util.tcl b/tests/support/util.tcl
index 36bc90d98..ae758f4cb 100644
--- a/tests/support/util.tcl
+++ b/tests/support/util.tcl
@@ -127,9 +127,23 @@ proc randomKey {} {
}
}
+proc findKeyWithType {r type} {
+ for {set j 0} {$j < 20} {incr j} {
+ set k [$r randomkey]
+ if {$k eq {}} {
+ return {}
+ }
+ if {[$r type $k] eq $type} {
+ return $k
+ }
+ }
+ return {}
+}
+
proc createComplexDataset {r ops} {
for {set j 0} {$j < $ops} {incr j} {
set k [randomKey]
+ set k2 [randomKey]
set f [randomValue]
set v [randomValue]
randpath {
@@ -158,6 +172,8 @@ proc createComplexDataset {r ops} {
$r zadd $k $d $v
} {
$r hset $k $f $v
+ } {
+ $r del $k
}
set t [$r type $k]
}
@@ -175,11 +191,23 @@ proc createComplexDataset {r ops} {
}
{set} {
randpath {$r sadd $k $v} \
- {$r srem $k $v}
+ {$r srem $k $v} \
+ {
+ set otherset [findKeyWithType r set]
+ if {$otherset ne {}} {
+ $r sunionstore $k2 $k $otherset
+ }
+ }
}
{zset} {
randpath {$r zadd $k $d $v} \
- {$r zrem $k $v}
+ {$r zrem $k $v} \
+ {
+ set otherzset [findKeyWithType r zset]
+ if {$otherzset ne {}} {
+ $r zunionstore $k2 2 $k $otherzset
+ }
+ }
}
{hash} {
randpath {$r hset $k $f $v} \