You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Subscriptions are handled using the `SubscriptionConnection`. Similar to the `TransactionConnection`, the `SubscriptionConnection` is constructed from an existing `RedisConnection`. Once created, the `SubscriptionConnection` maintains a simple event loop that will call the user's defined function whenever a message is received on the specified channel.
118
118
119
+
If the `subscribe_data` method is used for subscription then the callback function will be passed the `message` field of `SubscriptionMessage` instance. If the `subscribe` method is used for subscription, the callback will be passed a `SubscriptionMessage` directly, which contains the channel, message type and key as well.
120
+
119
121
```julia
120
122
x = Any[]
121
123
f(y) =push!(x, y)
122
124
sub =open_subscription(conn)
123
-
subscribe(sub, "baz", f)
125
+
subscribe_data(sub, "baz", f)
124
126
publish(conn, "baz", "foobar")
125
127
x # Returns ["foobar"]
126
128
```
@@ -129,9 +131,9 @@ Multiple channels can be subscribed together by providing a `Dict{String, Functi
129
131
130
132
```julia
131
133
x = Any[]
132
-
f(y::SubscriptionMessage) =push!(x, y)
134
+
f(y::SubscriptionMessage) =push!(x, y.message)
133
135
sub =open_subscription(conn)
134
-
d =Dict{String, Function}({"baz"=> f, "bar"=> println})
136
+
d =Dict{String, Function}({"baz"=> f, "bar"=>y->println(y.message)})
0 commit comments