Stackexchange.Redis Channel Subscription Patterns (exclusions)

Viewed 239

I'm attempting to write up a channel pattern for a Redis subscription such that, when my application is in Debug mode, I subscribe to all channels ending in _dev, but when not in debug mode, I subscribe to all channels that specifically don't end in _dev. My channels look something like: CommandChannel_<id> or CommandChannel_<id>_dev

I understand that, according to the documentation, "all glob-style patterns are valid", and so I've written up a pattern that I feel like should do the trick:

string subBase = "CommandChannel_"
redisSubscription.SubscribeAsync(subBase + "*" + (DEBUG ? "_dev": "!(_dev)"), async (channel, message) =>
{
    // Do stuff
}

What I'm finding is that, when in DEBUG mode, my subscription works fine - I correctly "catch" all messages over any channel matching the pattern of CommandChannel_<id>_dev. But when I change the application to not be in DEBUG mode, my subscription doesn't catch anything despite definitely publishing to appropriate channels (CommandChannel_<id>). As I understand it, !(_dev) should exclude any channels ending in _dev, but allow all other channels that I expect.

What am I missing here?

1 Answers

Redis itself does not support that usage; relevant docs:

Supported glob-style patterns:

  • h?llo subscribes to hello, hallo and hxllo
  • h*llo subscribes to hllo and heeeello
  • h[ae]llo subscribes to hello and hallo, but not hillo

Exclusions are not mentioned, and from testing in redis-cli: do not work. Suggestions:

  1. use separate servers/ports for prod and dev - not patterns
  2. use an active pattern (not the lack of a pattern) for all logical tiers/tenants
Related