1
0

bg_block_op.tcl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 client setname LOAD_HANDLER
  14. $r select $db
  15. for {set j 0} {$j < $ops} {incr j} {
  16. # List side
  17. set k list_[randomInt 10]
  18. set k2 list_[randomInt 10]
  19. set v [randomValue]
  20. randpath {
  21. randpath {
  22. $r rpush $k $v
  23. } {
  24. $r lpush $k $v
  25. }
  26. } {
  27. $r blpop $k 2
  28. } {
  29. $r blpop $k $k2 2
  30. }
  31. # Zset side
  32. set k zset_[randomInt 10]
  33. set k2 zset_[randomInt 10]
  34. set v1 [randomValue]
  35. set v2 [randomValue]
  36. randpath {
  37. $r zadd $k [randomInt 10000] $v
  38. } {
  39. $r zadd $k [randomInt 10000] $v [randomInt 10000] $v2
  40. } {
  41. $r bzpopmin $k 2
  42. } {
  43. $r bzpopmax $k 2
  44. }
  45. }
  46. }
  47. bg_block_op [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] [lindex $argv 3] [lindex $argv 4]