Get all keys from redis cache. It is very slow.

Vishweshwar-3323 40 Reputation points
2023-03-06T11:16:25.12+00:00

I am fetching all the keys from redis. But it takes a lot of time to fetch and sometimes it gives the error of timeout.

Here there 1 lakh 40k keys are created. I want a list of keys with or without patterns.

I am using azure cache for redis and not a local redis.
Thanks.

Azure Cache for Redis
Azure Cache for Redis
An Azure service that provides access to a secure, dedicated Redis cache, managed by Microsoft.
305 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SSingh-MSFT 16,371 Reputation points Moderator
    2023-03-07T06:24:56.4866667+00:00

    Hi @Vishweshwar-3323 ,

    Welcome to Microsoft Q&A forum.

    As I understand, you are fetching all the keys from Redis. But it takes a lot of time to fetch and sometimes it gives the error of timeout.

    Review the commands that you're issuing to your Redis server to understand their performance impacts. For instance, the KEYS command is often used without knowing that it's an O(N) operation. You can avoid KEYS by using SCAN to reduce CPU spikes.

    More options are illustrated here Investigating timeout exceptions in StackExchange.Redis for Azure Redis Cache

    Azure Cache for Redis works best with smaller values. Consider dividing bigger chunks of data in to smaller chunks to spread the data over multiple keys. Additional reference thread What is the ideal value size range for redis? Is 100KB too large?

    https://redis.com/blog/redis-clustering-best-practices-with-keys/

    Use Standard or Premium tier for production systems. Don't use the Basic tier in production. The Basic tier is a single node system with no data replication and no SLA. Also, use at least a C1 cache. C0 caches are only meant for simple dev/test scenarios because:

    • they share a CPU core
    • use little memory
    • are prone to noisy neighbor issues

    Hope this helps. Please let us know if you have further questions. Thank you.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.