Subscribe to one or more Redis PUB/SUB channels. This predicate
creates a thread using thread_create/3 with the given Options. Once
running, the thread listens for messages. The message content is a
string or Prolog term as described in redis/3. On receiving a
message, the following message is broadcasted:
redis(Id, Channel, Data)
If redis_unsubscribe/2 removes the last subscription, the thread
terminates.
To simply print the incomming messages use e.g.
?- listen(redis(_, Channel, Data),
format('Channel ~p got ~p~n', [Channel,Data])).
true.
?- redis_subscribe(default, test, Id, []).
Id = redis_pubsub_3,
?- redis(publish(test, "Hello world")).
Channel test got "Hello world"
1
true.
- Arguments:
-
Id | - is the thread identifier of the listening thread. Note that
the Options alias(Name) can be used to get a system wide name. |