Redis is slow while loop

已查看 91 次
跳至第一个未读帖子

Mohan Raj

未读,
2021年8月15日 18:29:312021/8/15
收件人 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

未读,
2021年9月1日 23:30:462021/9/1
收件人 Redis DB
Hi, How do you do a loop through all the keys in any way?

Greg Andrews

未读,
2021年9月2日 00:41:502021/9/2
收件人 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

未读,
2021年9月2日 01:06:392021/9/2
收件人 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

未读,
2021年9月2日 01:23:502021/9/2
收件人 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

未读,
2021年9月2日 01:25:192021/9/2
收件人 Redis DB
If all keys are string, you can use mget command.

Mohan Raj

未读,
2021年9月2日 01:29:572021/9/2
收件人 redi...@googlegroups.com
Sure let me try that.

Mehedi Hasan

未读,
2021年9月2日 02:10:192021/9/2
收件人 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

未读,
2021年9月2日 02:20:392021/9/2
收件人 redi...@googlegroups.com
回复全部
回复作者
转发
0 个新帖子