]>
git.saurik.com Git - redis.git/blob - tests/unit/pubsub.tcl
10af8585647f1baa94cad4d271b13bbe741a1eaa
1 start_server
{tags
{"pubsub"}} {
2 test
"PUBLISH when no one is listening" {
3 assert_equal
0 [r publish chan hello
]
6 test
"SUBSCRIBE basics" {
7 set rd1
[redis_deferring_client
]
8 set rd2
[redis_deferring_client
]
10 # subscribe first client to two channels
11 $rd1 subscribe chan1 chan2
12 assert_equal
{subscribe chan1
1} [$rd1 read]
13 assert_equal
{subscribe chan2
2} [$rd1 read]
15 # publish on both channels
16 assert_equal
1 [r publish chan1 hello
]
17 assert_equal
1 [r publish chan2 world
]
18 assert_equal
{message chan1 hello
} [$rd1 read]
19 assert_equal
{message chan2 world
} [$rd1 read]
21 # subscribe second client to one channel
23 assert_equal
{subscribe chan1
1} [$rd2 read]
25 # publish on channel with two subscribers
26 assert_equal
2 [r publish chan1 hello
]
27 assert_equal
{message chan1 hello
} [$rd1 read]
28 assert_equal
{message chan1 hello
} [$rd2 read]
30 # unsubscribe first client from all channels
33 assert_equal
"unsubscribe" [lindex $msg 0]
34 assert_match
"chan*" [lindex $msg 1]
35 assert_match
1 [lindex $msg 2]
37 assert_equal
"unsubscribe" [lindex $msg 0]
38 assert_match
"chan*" [lindex $msg 1]
39 assert_match
0 [lindex $msg 2]
41 # publish on channel with only remaining subscriber
42 assert_equal
1 [r publish chan1 hello
]
43 assert_equal
{message chan1 hello
} [$rd2 read]