# How would one implement a sorted list like Redis

**URL:** <https://discuss.aerospike.com/t/how-would-one-implement-a-sorted-list-like-redis/1046>\
**Category:** Node.js Client\
**Created:** [March 11, 2015, 3:42pm UTC](https://discuss.aerospike.com/t/how-would-one-implement-a-sorted-list-like-redis/1046 "2015-03-11T15:42:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhongcai\_Ng](https://avatars.discourse-cdn.com/v4/letter/z/b5a626/32.png) [@Zhongcai\_Ng](https://discuss.aerospike.com/u/Zhongcai_Ng)\
**Post date:** [March 11, 2015, 3:42pm UTC](https://discuss.aerospike.com/t/how-would-one-implement-a-sorted-list-like-redis/1046/1 "2015-03-11T15:42:13Z")

</div>

Hi guys,

In the case of a leader scoreboard (score - PlayerID), 2 LLISTs? One ordered list (Score-PlayerID) and another (PlayerID-Score)? With a number of PlayerIDs key-maps. And a UDF iterating through the LLISTs to retrieve the individual PlayerID key-maps? This seems quite convoluted. Appreciate any help… =)

---

<div class="post-metadata">

**Author:** ![iamontheinet](https://avatars.discourse-cdn.com/v4/letter/i/b3f665/32.png) [@iamontheinet](https://discuss.aerospike.com/u/iamontheinet)\
**Post date:** [March 12, 2015, 12:55am UTC](https://discuss.aerospike.com/t/how-would-one-implement-a-sorted-list-like-redis/1046/2 "2015-03-12T00:55:52Z")

</div>

Hi,

Pl read this recent post which talks about finding “top 10” (which aligns with a leaderboard use case) using Aerospike Aggregations - [http://www.aerospike.com/blog/top-10-aerospike-aggregations/](http://www.aerospike.com/blog/top-10-aerospike-aggregations/)

You will find that most of the work is done in UDFs (written in Lua) so the implementation described in the post is client-language agnostic for the most part.

I hope this helps you get started.

---

<div class="post-metadata">

**Author:** ![raj](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@raj](https://discuss.aerospike.com/u/raj)\
**Post date:** [March 12, 2015, 7:45am UTC](https://discuss.aerospike.com/t/how-would-one-implement-a-sorted-list-like-redis/1046/5 "2015-03-12T07:45:27Z")

</div>

On the related note. I am assuming you mean Redis Sorted Set.

Given that your sort key (score) and your lookup key (id) are different only way to solve this is to have two structure one for sorting and another one for lookup. This is precisly Sorted Set in Redis does internally as well it has sorted list of score and hash for unique id.

So you have to write UDF to deal with two llist.

Can you share some more detail. Is it only

player-id-score or is there some more associated data …

– R

---

<div class="post-metadata">

**Author:** ![Zhongcai\_Ng](https://avatars.discourse-cdn.com/v4/letter/z/b5a626/32.png) [@Zhongcai\_Ng](https://discuss.aerospike.com/u/Zhongcai_Ng)\
**Post date:** [March 13, 2015, 8:20am UTC](https://discuss.aerospike.com/t/how-would-one-implement-a-sorted-list-like-redis/1046/6 "2015-03-13T08:20:53Z")

</div>

Hi Raj, how would you handle identical scores by different players? In which case, one of our LList will have 2 similar keys (scores) with different values (player)

---

<div class="post-metadata">

**Author:** ![raj](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@raj](https://discuss.aerospike.com/u/raj)\
**Post date:** [March 13, 2015, 8:38am UTC](https://discuss.aerospike.com/t/how-would-one-implement-a-sorted-list-like-redis/1046/7 "2015-03-13T08:38:26Z")

</div>

LLIST supports duplicate values but it in Beta.

The alternative mechanism would be making the key score\_id string which should give you keys sorted based on score, and appending id makes it unique as well. You can perform range query to get all the id with particular score …

– R

---

<div class="post-metadata">

**Author:** ![Zhongcai\_Ng](https://avatars.discourse-cdn.com/v4/letter/z/b5a626/32.png) [@Zhongcai\_Ng](https://discuss.aerospike.com/u/Zhongcai_Ng)\
**Post date:** [March 13, 2015, 9:21am UTC](https://discuss.aerospike.com/t/how-would-one-implement-a-sorted-list-like-redis/1046/8 "2015-03-13T09:21:23Z")

</div>

By beta, you mean to say, it will be supported in Aerospike v4?? Great idea to convert the score to string and then appending it with the playerID. Thanks!

---

<div class="post-metadata">

**Author:** ![raj](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@raj](https://discuss.aerospike.com/u/raj)\
**Post date:** [March 13, 2015, 10:10am UTC](https://discuss.aerospike.com/t/how-would-one-implement-a-sorted-list-like-redis/1046/9 "2015-03-13T10:10:56Z")

</div>

Beta means it works but there may be lingering bugs :). It should get become GA in future … (no timelines though)

– R
