diff options
author | Hanna Fadida <hanna.fadida@redislabs.com> | 2021-04-19 21:33:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-19 21:33:26 +0300 |
commit | 53a4d6c3b152a9aa6386c2362400b258cec09ed3 (patch) | |
tree | 7ab3ed530bc67cf90d2f8a2ed504f52b043dc243 /tests/support/util.tcl | |
parent | f40ca9cb58049683b563245006892001a5ebfacd (diff) | |
download | redis-53a4d6c3b152a9aa6386c2362400b258cec09ed3.tar.gz |
Modules: adding a module type for key space notification (#8759)
Adding a new type mask for key space notification, REDISMODULE_NOTIFY_MODULE, to enable unique notifications from commands on REDISMODULE_KEYTYPE_MODULE type keys (which is currently unsupported).
Modules can subscribe to a module key keyspace notification by RM_SubscribeToKeyspaceEvents,
and clients by notify-keyspace-events of redis.conf or via the CONFIG SET, with the characters 'd' or 'A'
(REDISMODULE_NOTIFY_MODULE type mask is part of the '**A**ll' notation for key space notifications).
Refactor: move some pubsub test infra from pubsub.tcl to util.tcl to be re-used by other tests.
Diffstat (limited to 'tests/support/util.tcl')
-rw-r--r-- | tests/support/util.tcl | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/support/util.tcl b/tests/support/util.tcl index 318cdf871..b00aa159a 100644 --- a/tests/support/util.tcl +++ b/tests/support/util.tcl @@ -713,3 +713,52 @@ proc chi_square_value {res} { return $x2_value } + +#subscribe to Pub/Sub channels +proc consume_subscribe_messages {client type channels} { + set numsub -1 + set counts {} + + for {set i [llength $channels]} {$i > 0} {incr i -1} { + set msg [$client read] + assert_equal $type [lindex $msg 0] + + # when receiving subscribe messages the channels names + # are ordered. when receiving unsubscribe messages + # they are unordered + set idx [lsearch -exact $channels [lindex $msg 1]] + if {[string match "*unsubscribe" $type]} { + assert {$idx >= 0} + } else { + assert {$idx == 0} + } + set channels [lreplace $channels $idx $idx] + + # aggregate the subscription count to return to the caller + lappend counts [lindex $msg 2] + } + + # we should have received messages for channels + assert {[llength $channels] == 0} + return $counts +} + +proc subscribe {client channels} { + $client subscribe {*}$channels + consume_subscribe_messages $client subscribe $channels +} + +proc unsubscribe {client {channels {}}} { + $client unsubscribe {*}$channels + consume_subscribe_messages $client unsubscribe $channels +} + +proc psubscribe {client channels} { + $client psubscribe {*}$channels + consume_subscribe_messages $client psubscribe $channels +} + +proc punsubscribe {client {channels {}}} { + $client punsubscribe {*}$channels + consume_subscribe_messages $client punsubscribe $channels +}
\ No newline at end of file |