2
0

keyspace_events.tcl 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. set testmodule [file normalize tests/modules/keyspace_events.so]
  2. tags "modules" {
  3. start_server [list overrides [list loadmodule "$testmodule"]] {
  4. test {Test loaded key space event} {
  5. r set x 1
  6. r hset y f v
  7. r lpush z 1 2 3
  8. r sadd p 1 2 3
  9. r zadd t 1 f1 2 f2
  10. r xadd s * f v
  11. r debug reload
  12. assert_equal {1 x} [r keyspace.is_key_loaded x]
  13. assert_equal {1 y} [r keyspace.is_key_loaded y]
  14. assert_equal {1 z} [r keyspace.is_key_loaded z]
  15. assert_equal {1 p} [r keyspace.is_key_loaded p]
  16. assert_equal {1 t} [r keyspace.is_key_loaded t]
  17. assert_equal {1 s} [r keyspace.is_key_loaded s]
  18. }
  19. test {Nested multi due to RM_Call} {
  20. r del multi
  21. r del lua
  22. r set x 1
  23. r set x_copy 1
  24. r keyspace.del_key_copy x
  25. r keyspace.incr_case1 x
  26. r keyspace.incr_case2 x
  27. r keyspace.incr_case3 x
  28. assert_equal {} [r get multi]
  29. assert_equal {} [r get lua]
  30. r get x
  31. } {3}
  32. test {Nested multi due to RM_Call, with client MULTI} {
  33. r del multi
  34. r del lua
  35. r set x 1
  36. r set x_copy 1
  37. r multi
  38. r keyspace.del_key_copy x
  39. r keyspace.incr_case1 x
  40. r keyspace.incr_case2 x
  41. r keyspace.incr_case3 x
  42. r exec
  43. assert_equal {1} [r get multi]
  44. assert_equal {} [r get lua]
  45. r get x
  46. } {3}
  47. test {Nested multi due to RM_Call, with EVAL} {
  48. r del multi
  49. r del lua
  50. r set x 1
  51. r set x_copy 1
  52. r eval {
  53. redis.pcall('keyspace.del_key_copy', KEYS[1])
  54. redis.pcall('keyspace.incr_case1', KEYS[1])
  55. redis.pcall('keyspace.incr_case2', KEYS[1])
  56. redis.pcall('keyspace.incr_case3', KEYS[1])
  57. } 1 x
  58. assert_equal {} [r get multi]
  59. assert_equal {1} [r get lua]
  60. r get x
  61. } {3}
  62. test {Test module key space event} {
  63. r keyspace.notify x
  64. assert_equal {1 x} [r keyspace.is_module_key_notified x]
  65. }
  66. test "Keyspace notifications: module events test" {
  67. r config set notify-keyspace-events Kd
  68. r del x
  69. set rd1 [redis_deferring_client]
  70. assert_equal {1} [psubscribe $rd1 *]
  71. r keyspace.notify x
  72. assert_equal {pmessage * __keyspace@9__:x notify} [$rd1 read]
  73. $rd1 close
  74. }
  75. }
  76. }