Search code examples
algorithmcachingdata-structuresredishashtable

Looking for advice on effectively using REDIS Cache in a large application


We have a use case where we have to store some user IDs(testUserId) in REDIS and mark them as test users temporarily and also mark a testingMode Flag as active/inactive. We would have to then in an API check if the testingMode is active and then passed user ID is a test user or not.

So far what I have done is store a flag and an array containing list of users.

The issue with this implementation is that while checking we have to fetch the whole data from REDIS and convert that into List(array) and see if the testUserId is present or not. Some people have raised concerns over this being ineffective.

Is there any better way to do this?

I thought of storing testUserId as a key and testingMode flag as a value but then it will create too many rows. Will this be the best way or are there any better ways for this?


Solution

  • I would recommend storing a set of test users, and use https://redis.io/commands/exists to see if your current user is a test user.

    This only has to lookup the test user. And since very few of your users are expected to be test users, this stores very little data.

    Please note that you should pay close attention to space usage with Redis. It runs wonderfully...until your data gets too big for RAM and then it performs terribly. So try to keep it from getting too big unnecessarily!