0

Question about cache (Redis or other distribuated cache).
So I would like to find a solution with “Partioning”. But without code it my self (ofc)
Ok, example :
In the application you have clients, each client has users, each user has role.
So right now it’s in the cache with the keu “User:<userId>” = role
Sometimes, when you change client settings, all entries should be removed.
So what I would love to have :
Client_Id/UsersRoles/UserId as a key
And I would love to be able tp delete “all keys after /” :
Basiclly delete client_id/ would delete everything in cache for this client
Delete client_id/UserRoles will clean up all saved roles.
I’m pretty new working with redis, but it doesn’t seem possible out of the box.
Any reading material I could read ?

Comments
  • 0
    It's not possible out of the box.

    Usually you use SCAN and delete queries matching the result to not block and let the server hang.

    https://redis.io/commands/scan/

    The question is usually how long this takes....

    Redis is a CACHE. Not a persistent storage.

    So the question is in my opinion: How can you make sure that the "timeline" fits?

    Timeline like:

    Add cache - old settings
    Add cache - old settings
    Delete starts
    Add cache - new settings
    Add cache - new settings
    ...

    So as soon as the Delete starts, newly added keys must be different from previous keys.

    Same for read keys - obviously. If read keys do not match the new settings, delete and readd.

    That way it doesn't matter how long the deletion of old keys takes, you can be certain that every cache read / add uses new data and that the purging of stale cache data won't influence it.
  • 0
    Hint: Versioning. :)
  • 0
    @IntrusionCM Redis does have a function to delete multiple keys in a single operation.

    But it would involve on my end to track the “portioning” (Sorry, couldn’t think of a better word).

    But now you have multiple instances (In RAM) needed to be synchronized and.. Well, redis is already here, right?

    I think it can be solved, but I never found a lib which does it.

    Ok,. And know weed is talking :

    But we can have that “state of redis” in ram on each instance using it (Yep, some memory issues might happen).

    And instead of redis, we use SignalR to synch.

    Which is already fully functioning in our app with cross servers etc. (We have stateless Azure functions to be able to display real time progress bar on a completely separated server).
  • 0
    @NoToJavaScript yes it has a function to delete multiple keys.

    You would do SCAN - DELETE - ....
Add Comment