Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 488 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is there a way to set a members limit on a redis sorted set?

#1
Say I want to store the 10 most recent additions to a redis sorted set where the 11th addition pushes the 1st off the list. And until it reaches 10 items it just grows normally.

Do I have to check the length on each addition myself and delete the 1st element?
Reply

#2
I don't think you need to check the length, but have to cap it yourself:

`ZREMRANGEBYRANK [KEY] 0 -10`
Reply

#3
if you just need to remove first member into ZSet
you can use this command :

ZREMRANGEBYRANK key 0 0

you can also sort 11th element as first member in ZSet using ZADD with score 1 :

ZADD key 1 member

EX:

>
redis 127.0.0.1:6379> ZADD myzset 1 one
(integer) 1
redis 127.0.0.1:6379> ZADD myzset 1 two
(integer) 1
redis 127.0.0.1:6379> ZRANGE myzset 0 -1 withscores
1) "one"
2) "1"
3) "two"
4) "1"
redis 127.0.0.1:6379> ZREMRANGEBYRANK myzset 0 0
(integer) 1
redis 127.0.0.1:6379> ZADD myzset 1 three
(integer) 1
redis 127.0.0.1:6379> ZRANGE myzset 0 -1 withscores
1) "three"
2) "1"
3) "two"
4) "1"
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through