2
0

tracking.tcl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. start_server {tags {"tracking"}} {
  2. # Create a deferred client we'll use to redirect invalidation
  3. # messages to.
  4. set rd1 [redis_deferring_client]
  5. $rd1 client id
  6. set redir [$rd1 read]
  7. $rd1 subscribe __redis__:invalidate
  8. $rd1 read ; # Consume the SUBSCRIBE reply.
  9. test {Clients are able to enable tracking and redirect it} {
  10. r CLIENT TRACKING on REDIRECT $redir
  11. } {*OK}
  12. test {The other connection is able to get invalidations} {
  13. r SET a 1
  14. r GET a
  15. r INCR a
  16. r INCR b ; # This key should not be notified, since it wasn't fetched.
  17. set keys [lindex [$rd1 read] 2]
  18. assert {[llength $keys] == 1}
  19. assert {[lindex $keys 0] eq {a}}
  20. }
  21. test {The client is now able to disable tracking} {
  22. # Make sure to add a few more keys in the tracking list
  23. # so that we can check for leaks, as a side effect.
  24. r MGET a b c d e f g
  25. r CLIENT TRACKING off
  26. }
  27. test {Clients can enable the BCAST mode with the empty prefix} {
  28. r CLIENT TRACKING on BCAST REDIRECT $redir
  29. } {*OK*}
  30. test {The connection gets invalidation messages about all the keys} {
  31. r MSET a 1 b 2 c 3
  32. set keys [lsort [lindex [$rd1 read] 2]]
  33. assert {$keys eq {a b c}}
  34. }
  35. test {Clients can enable the BCAST mode with prefixes} {
  36. r CLIENT TRACKING off
  37. r CLIENT TRACKING on BCAST REDIRECT $redir PREFIX a: PREFIX b:
  38. r MULTI
  39. r INCR a:1
  40. r INCR a:2
  41. r INCR b:1
  42. r INCR b:2
  43. r EXEC
  44. # Because of the internals, we know we are going to receive
  45. # two separated notifications for the two different prefixes.
  46. set keys1 [lsort [lindex [$rd1 read] 2]]
  47. set keys2 [lsort [lindex [$rd1 read] 2]]
  48. set keys [lsort [list {*}$keys1 {*}$keys2]]
  49. assert {$keys eq {a:1 a:2 b:1 b:2}}
  50. }
  51. test {Adding prefixes to BCAST mode works} {
  52. r CLIENT TRACKING on BCAST REDIRECT $redir PREFIX c:
  53. r INCR c:1234
  54. set keys [lsort [lindex [$rd1 read] 2]]
  55. assert {$keys eq {c:1234}}
  56. }
  57. $rd1 close
  58. }