Skip to content

How to Implement Redis Pub/Sub #81

Answered by ioquatix
ttanimichi asked this question in Q&A
Discussion options

You must be logged in to vote

Since both connection.read and context.listen are waiting in loops, there are nested infinite loops. Is this method acceptable without causing any issues?

It is fine to do that. connection.read is blocking and may fail if the remote end goes away. Similar with context.listen.

The part where Async::Redis::Client.new is wrapped in a Sync block. Is this necessary?

No, it's not necessary. A client is not a connection, but just a way to make a connection of a certain kind (in this case, a subscription). I've updated the example showing how I'd do it: https://github.com/socketry/async-websocket-pubsub-example

Should the Redis client be a global variable like $connections?

You should avoid…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@ttanimichi
Comment options

@ioquatix
Comment options

@ttanimichi
Comment options

@ioquatix
Comment options

@ttanimichi
Comment options

Answer selected by ttanimichi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants