Redis is slow while loop

88 views
Skip to first unread message

Mohan Raj

unread,
Aug 15, 2021, 6:29:31 PM8/15/21
to Redis DB
Hi Guys,
I am having a use case where i have a loop and read redis based on keys.

On an avg to loop size of 30000, it is taking more than 30 secs from Java Jedis Library.

Any thoughts or suggestions please.

sundb

unread,
Sep 1, 2021, 11:30:46 PM9/1/21
to Redis DB
Hi, How do you do a loop through all the keys in any way?

Greg Andrews

unread,
Sep 2, 2021, 12:41:50 AM9/2/21
to Redis DB
"KEYS *" will return the list of key names to the client, then the client can iterate over the list, sending a command for each key (perhaps 'TTL keyname' or 'EXPIRETIME keyname').

My suggestion to the original poster is an echo of the warning message found in the description of the KEYS command at:  https://redis.io/commands/keys

    It may ruin performance when it is executed against large databases. This command is intended for debugging and special operations,
    such as changing your keyspace layout. Don't use KEYS in your regular application code. If you're looking for a way to find keys
    in a subset of your keyspace, consider using SCAN or sets.

Mohan Raj

unread,
Sep 2, 2021, 1:06:39 AM9/2/21
to redi...@googlegroups.com
Hey,
We form the key from the client and get it from redis using get keys.

Which is taking time even if I set the no of client connections to the maximum.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/redis-db/ea309503-aa9c-4514-a928-dad2c0b3efe5n%40googlegroups.com.

sundb

unread,
Sep 2, 2021, 1:23:50 AM9/2/21
to Redis DB
If you're sending 30,000 get commands, it's really going to be slow.
You might consider using the redis pipeline to send all your commands to redis at once.

sundb

unread,
Sep 2, 2021, 1:25:19 AM9/2/21
to Redis DB
If all keys are string, you can use mget command.

Mohan Raj

unread,
Sep 2, 2021, 1:29:57 AM9/2/21
to redi...@googlegroups.com
Sure let me try that.

Mehedi Hasan

unread,
Sep 2, 2021, 2:10:19 AM9/2/21
to redi...@googlegroups.com
Keys is a blocking command. You can try scan if you know the naming patters of your redis keys beforehand.  

Mohan Raj

unread,
Sep 2, 2021, 2:20:39 AM9/2/21
to redi...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages