2
0

bg_block_op.tcl 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. source tests/support/redis.tcl
  2. source tests/support/util.tcl
  3. set ::tlsdir "tests/tls"
  4. # This function sometimes writes sometimes blocking-reads from lists/sorted
  5. # sets. There are multiple processes like this executing at the same time
  6. # so that we have some chance to trap some corner condition if there is
  7. # a regression. For this to happen it is important that we narrow the key
  8. # space to just a few elements, and balance the operations so that it is
  9. # unlikely that lists and zsets just get more data without ever causing
  10. # blocking.
  11. proc bg_block_op {host port db ops tls} {
  12. set r [redis $host $port 0 $tls]
  13. $r select $db
  14. for {set j 0} {$j < $ops} {incr j} {
  15. # List side
  16. set k list_[randomInt 10]
  17. set k2 list_[randomInt 10]
  18. set v [randomValue]
  19. randpath {
  20. randpath {
  21. $r rpush $k $v
  22. } {
  23. $r lpush $k $v
  24. }
  25. } {
  26. $r blpop $k 2
  27. } {
  28. $r blpop $k $k2 2
  29. }
  30. # Zset side
  31. set k zset_[randomInt 10]
  32. set k2 zset_[randomInt 10]
  33. set v1 [randomValue]
  34. set v2 [randomValue]
  35. randpath {
  36. $r zadd $k [randomInt 10000] $v
  37. } {
  38. $r zadd $k [randomInt 10000] $v [randomInt 10000] $v2
  39. } {
  40. $r bzpopmin $k 2
  41. } {
  42. $r bzpopmax $k 2
  43. }
  44. }
  45. }
  46. bg_block_op [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] [lindex $argv 3] [lindex $argv 4]