I would like to destroy all sessions of a user or a customer who resets his/her password. Sessions are stored in Redis with a prefix of sess in their key such as sess:-V53mZvQT9PNXPy_1DD-XeR-gFM7cQ8m .
I found two methods to access Redis
cacheServiceinitializefunction from@medusajs/cache-redismodule
Both provides the same methods: get, set, invalidate.
Both get and invalidate should be provided with a specific key to get or invalidate.
Since the keys for the session of a user/customer in Redis are totally random, I don't know from how many devices a user has logged it and, how to get the whole valid sessions of a user/customer and how to delete them.
I came up with the idea of getting the whole keys from Redis which starts with sess and then checking all of them if they are related to the expected user and then invalidate it. But I do not have any method to do this from cacheService, nor from initialize . Besides, I can have millions of sessions in production and this does not seem to be the right way to do it.
Does Medusa have anything for such a thing (any helper to get the whole sessions of a user or invalidate it), or anything that can help me do what I want?
Can you please provide your ideas down here if Medusa hasn't considered it yet?