Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorted set of a fixed size in Redis?

Tags:

redis

I'm a rookie in using Redis, and recently have a problem when I'm thinking the solution to handle the case of high concurrency in out system, I want to use Redis, everybody know access from In-Memory is great faster than IO. Redis sorted set is the possible tool for use to do it, we want to a fixed size of sorted set to contain the user's mobile number, I Googled/Baidued a lot, didn't find any meaning message, so can anybody tell me How to specify Redis Sorted Set a fixed size? And set should tell me any add operation to sorted set is success or not?

Thanks

like image 524
Brady Zhu Avatar asked Mar 15 '23 19:03

Brady Zhu


1 Answers

I don't think you can specify a size, that you will have to check it yourself.

You can use ZCARD

ZCARD KEY

Or you could just remove the first element ZREMRANGEBYRANK

[ZREMRANGEBYRANK][2] [KEY] 0 -[YOURSIZE]
like image 179
Basit Anwer Avatar answered Mar 19 '23 20:03

Basit Anwer