FreeRedis icon indicating copy to clipboard operation
FreeRedis copied to clipboard

ClientSideCaching not being notified when key is removed from Redis

Open MartyBJones opened this issue 4 years ago • 20 comments

I was under the impression that the client side cache would be notified if it contains a key that was removed from Redis and would remove itself from the local cache. I have an item in the local cache and I removed the item from Redis but the item still remains in the local cache after removing.

Is this not the case?

MartyBJones avatar May 19 '21 14:05 MartyBJones

By the way, I noticed that if I make a call to flushDB from Redis then it does clear the whole local cache. I just don't see individual removals from Redis being sent to the local cache for removal.

MartyBJones avatar May 19 '21 15:05 MartyBJones

I am not noticing that sometimes I see the invalidate method being invoked on the client and sometimes not. Any idea why the client would not receive the invalidate event?

MartyBJones avatar May 20 '21 18:05 MartyBJones

This function relies on redis6.0.

_cli.Subscribe("__redis__:invalidate", InValidate);

You need to debug the source code for the subscription event.

2881099 avatar May 21 '21 00:05 2881099

I have debugged the code and I get some invalidation events but not all of them which is the problem. What I don’t understand is why I get some but not others.

On Thu, May 20, 2021 at 8:39 PM 2881099 @.***> wrote:

This function relies on redis6.0.

_cli.Subscribe("redis:invalidate", InValidate);

You need to debug the source code for the subscription event.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/2881099/FreeRedis/issues/63#issuecomment-845572107, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA562VVDKB4A5X7DCWWSGBLTOWTUPANCNFSM45E3BS2Q .

MartyBJones avatar May 21 '21 01:05 MartyBJones

Redis subscribe may lose data. For example, the notification before the program starts cannot be obtained.

You can start a redis cli client subscription to see if it will be lost.

2881099 avatar May 21 '21 01:05 2881099

Here is what I am seeing. I am running redis 6 and start a client A. For the first few adds and removes I see the invalidation event fire. After a few minutes if I open another client B and remove an item that I know is in the local cache of client A. I don’t see the invalidation event come through on client A and the local cache keeps the entry even thought it has been removed on the server.

On Thu, May 20, 2021 at 9:56 PM 2881099 @.***> wrote:

Redis subscribe may lose data. For example, the notification before the program starts cannot be obtained.

You can start a redis cli client subscription to see if it will be lost.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/2881099/FreeRedis/issues/63#issuecomment-845595949, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA562VTDD6DVISNY4IL5P6DTOW4WDANCNFSM45E3BS2Q .

MartyBJones avatar May 21 '21 02:05 MartyBJones

It's true that you won't fail the notification.

Client B needs to bind the subscriber's client ID with the "client tracking" command in advance to notify it of invalid data.

redis-cli
client tracking ON REDIRECT 1 ...
del key1
set key1 val1

REDIRECT ClientID

2881099 avatar May 21 '21 02:05 2881099

I am new to Redis so bear with me.

I am using redis client in web application and within a few web services. Each client needs to know if an item is invalidated from any client. How do I configure each client to support that?

On Thu, May 20, 2021 at 10:11 PM 2881099 @.***> wrote:

It's true that you won't fail the notification.

Client B needs to bind the subscriber's client ID with the "client tracking" command in advance to notify it of invalid data.

redis-cli client tracking ON REDIRECT 1 ... del key1 set key1 val1

REDIRECT ClientID

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/2881099/FreeRedis/issues/63#issuecomment-845600768, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA562VUPNS6ED7JFJVQ5Q4TTOW6LXANCNFSM45E3BS2Q .

MartyBJones avatar May 21 '21 02:05 MartyBJones

After each end connects to redis server, execute client tracking on direct 1

2881099 avatar May 21 '21 03:05 2881099

You have to know in advance which client is the subscriber, which has a ClientID (unique ID).

2881099 avatar May 21 '21 03:05 2881099

Does freeredis use two connections (one for data and one for invalidation) or just a single connection for both?

On Thu, May 20, 2021 at 11:41 PM 2881099 @.***> wrote:

You have to know in advance which client is the subscriber, which has a ClientID (unique ID).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/2881099/FreeRedis/issues/63#issuecomment-845629739, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA562VTS3SXZ7QIC3GAXLNDTOXI5PANCNFSM45E3BS2Q .

MartyBJones avatar May 21 '21 14:05 MartyBJones

Freeredis is a 1 + n connection mode.

1 independent invalid subscription connection.

Connection of N processing commands.

2881099 avatar May 21 '21 14:05 2881099

Ok good to know. What mode is the client cache running in? Is it standard or broadcasting mode?

Just trying to figure out how I can receive some invalidations but not others. It doesn’t make sense why it works for some but not others.

On Fri, May 21, 2021 at 10:21 AM 2881099 @.***> wrote:

Freeredis is a 1 + n connection mode.

1 independent invalid subscription connection.

Connection of N processing commands.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/2881099/FreeRedis/issues/63#issuecomment-845984599, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA562VUQXIHS7CSF5FS4X7LTOZT7ZANCNFSM45E3BS2Q .

MartyBJones avatar May 21 '21 14:05 MartyBJones

client tracking ON REDIRECT 1 ...

You can understand this command. We use this command.

2881099 avatar May 21 '21 14:05 2881099

I follow you now. One more question. Does your client use a connectionmultiplexer or does it pool connections?

On Fri, May 21, 2021 at 10:35 AM 2881099 @.***> wrote:

client tracking ON REDIRECT 1 ...

You can understand this command. We use this command.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/2881099/FreeRedis/issues/63#issuecomment-845994263, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA562VS3Q2YDT2VJF7PLDEDTOZVSXANCNFSM45E3BS2Q .

MartyBJones avatar May 21 '21 15:05 MartyBJones

I follow you now. One more question. Does your client use a connectionmultiplexer or does it pool connections?

Pool connections

2881099 avatar May 22 '21 00:05 2881099

I have another question. Is creating the RedisClient as a singleton the correct approach for a web app?

I just want to make sure I am instantiating the client correctly.

On Fri, May 21, 2021 at 8:53 PM 2881099 @.***> wrote:

I follow you now. One more question. Does your client use a connectionmultiplexer or does it pool connections?

Pool connections

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/2881099/FreeRedis/issues/63#issuecomment-846323513, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA562VU65MHCEKKVHG5C7E3TO357DANCNFSM45E3BS2Q .

MartyBJones avatar May 22 '21 20:05 MartyBJones

I think I may see what is going on. One of the services I am attempting to use Redis with is a WCF service. When I instantiate the RedisClient I see that a connection is created but the "Connected" event is not being fired on the ClientSideCaching class so the separate connection for invalidation events is never being setup. Any ideas on what would cause the "Connected" event to not fire?

MartyBJones avatar May 24 '21 14:05 MartyBJones

I have another question. Is creating the RedisClient as a singleton the correct approach for a web app? I just want to make sure I am instantiating the client correctly. … On Fri, May 21, 2021 at 8:53 PM 2881099 @.***> wrote: I follow you now. One more question. Does your client use a connectionmultiplexer or does it pool connections? Pool connections — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#63 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA562VU65MHCEKKVHG5C7E3TO357DANCNFSM45E3BS2Q .

It's the same. It's all single cases.

2881099 avatar May 24 '21 16:05 2881099

I am struggling to understand how your client works. I create a singleton instance of your client and enable client side caching. after I make several calls I am seeing your client creates several connections and it seems to lose the redirect connection when a new data connection is created. Have you successfully used your client within an ASP.NET MVC application?

MartyBJones avatar May 25 '21 00:05 MartyBJones