Skip to content

Instantly share code, notes, and snippets.

@kommradHomer
Last active May 31, 2019 23:08
Show Gist options
  • Save kommradHomer/ef3f6127ff845adbeee2a051a87c5692 to your computer and use it in GitHub Desktop.
Save kommradHomer/ef3f6127ff845adbeee2a051a87c5692 to your computer and use it in GitHub Desktop.
sorted set FIFO
...
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