Skip to content

Can't consume bulk keys from Invalidate channel #2507

@atamanber

Description

@atamanber

Hi.

To implement client-side caching, I have subscribed to "redis:invalidate" channel in my application as described in the article, and the application can consume invalidated messages successfully when another connection updates a key. Below is how my application connects to channel:

IConnectionMultiplexer _connection; //Initialized at startup. 
RedisChannel _invalidationChannel = new("__redis__:invalidate", RedisChannel.PatternMode.Auto);
ISubscriber subscriber = _connection.GetSubscriber()
subscriber.Subscribe(_invalidationChannel)?.OnMessage(OnMessage);
_connectionFacade.Execute("CLIENT", "TRACKING", "on", "REDIRECT", connectionId, "BCAST", "NOLOOP");

private void OnMessage(ChannelMessage message)
{
    try
    {
        _logger.LogDebug(message.Message.ToString());
    }
    catch(Exception ex)
    {
        _logger.LogError(ex, "Error RedisInvalidator.OnMessage: {message}", ex.Message);
    }
}

However, if I use bulk commands like MSET, MDEL or transactional update from another application with multiple variables, StackExchange.Redis doesn't consume any invalidation messages. Redis server is able to send a single invalidation message for multiple keys, which I tested by subscribing by terminal. If I apply MSET command with one key-value pair, I can consume it in the application however if I apply it with multiple key-value pairs then I can't consume it. Also no exceptions are thrown from the library.

As shown in below, for testing purposes I opened two terminals, left one was listening the invalidation channel, and right one was updating the Redis. First, I applied "MSET test 123"(right terminal) and this one is consumed by left-hand terminal and by my application as well. However when I applied "MSET test 123 test2 123"(right terminal), it was only consumed by left-hand terminal. My application couldn't consume it. Be aware that invalidation message consist list of keys that are invalidated when there is a multiple invalidation.

invalidation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions