Last active
May 31, 2019 23:08
-
-
Save kommradHomer/ef3f6127ff845adbeee2a051a87c5692 to your computer and use it in GitHub Desktop.
sorted set FIFO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
Jedis j; | |
j.connect(); | |
/* | |
*using NX parameter on ZADD command -> ADD IF NOT EXISTS -> UNIQUE | |
*using Timestamp as score -> always increasing -> always MAX score -> Like RPUSH on a list | |
*minimum score = oldest element -> ZPOPMIN will always give the oldest element. Like LPOP on a List | |
*/ | |
j.zadd("foo", Instant.now().toEpochMilli(),"aa", ZAddParams.zAddParams().nx()); | |
j.zadd("foo", Instant.now().toEpochMilli(),"bb", ZAddParams.zAddParams().nx()); | |
j.zadd("foo", Instant.now().toEpochMilli(),"cc", ZAddParams.zAddParams().nx()); | |
j.zadd("foo", Instant.now().toEpochMilli(),"dd", ZAddParams.zAddParams().nx()); | |
for(int i=0;i<4;i++) | |
j.zpopmin("foo"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment