question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

psubscribe patterns not working correctly?

See original GitHub issue

I’m trying to publish status messages for each process that gets forked within a script. Each channel is named as status_ followed by some unique identifier, job_id. So I was hoping to use psubscribe to subscribe to all channels matching the pattern status_*, but I’m having trouble doing so. It seems to work OK if I replace the call to redis.psubscribe with a regular redis.subscribe and hard-code the correct channel name, but that defeats the purpose.

redis.psubscribe('status_*', function(error, count){})
redis.on('message', function (channel, message) {
  console.log('Received message \'%s\' from channel \'%s\'', message, channel);
});

Then, on another script, I publish a message to the channel

  var channel = 'status_' + job_id;
  redis.subscribe(channel, function(error, count){
    pub.publish(channel, someMessage);
  });

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
klinquistcommented, Mar 23, 2016

@saschaishikawa Oh yes, one more thing… when you psubscribe, you need to watch for pmessage instead of message.

redis.on(‘pmessage’, function(channel, pattern, message) {});

😃

1reaction
ymeskinicommented, Jan 5, 2022

if everyone comes after the order has changed: sub.on('pmessage', (pattern, channel, message) => {})

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redis PSUBSCRIBE Problems - Stack Overflow
A server is sending a message via Redis on a channel composed of some name and a unique id. I need to essentially...
Read more >
Redis PSUBSCRIBE - How to subscribe to multiple patterns in ...
Learn how to subscribe to one or more patterns in redis message broker system using redis-cli. Redis PSUBSCRIBE command, Redis Tutorial.
Read more >
PSUBSCRIBE - Redis
Listen for messages published to channels matching the given patterns.
Read more >
Pub/Sub (Publish and Subscribe) - Eventide
Pub/Sub pattern is a messaging pattern that enables a loose coupling of ... attention to getting the message schemas right so that they...
Read more >
Publish-Subscribe Pattern: The Most Used Patterns in ...
Once the weather station issues a weather warning, they will do the following things: Building site: stop work; Ships: mooring; Tourists: cancel the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found