Kat
Kat

Reputation: 2500

Can I query the redis cache to get values by a list of keys?

I'm using the azure redis cache with a .NET implementation. I have a list of keys that I need to get from the cache. Right now, this is my implementation: `

        List<string> planIds = ...; // already initialized.
        List<customObj> plans = new List<customObj>();  
        foreach (string currentId in planIds)
        {
            var plan = Database.StringGet(key);
            if (plan != null) plans.Add(plan);
        }

I've simplified it a bit for my explanation, but it works just fine. However, I was wondering if I could do a similar setup to the batch set for the batch download by passing it a list of keys that I want to retrieve. It's usually around 200+ ids. Is that doable?

Upvotes: 2

Views: 5917

Answers (1)

serhiyb
serhiyb

Reputation: 4833

Have a look at StringGet overloaded method

You can pass an array of keys to get the array of values in single call.

It will execute Redis MGET call here

Upvotes: 5

Related Questions