I use Java Redis client "Jedis".
When getting a sorted set using zrange for example, the client specifies it returns a Set which by definition has no oredering guarantee.
this old question mentions the problem but I have found no reference to whether it is resolved.
Can I do this and know order will be preserved?
Set<String> results = jedisCli.zrange(key, start, end);
MyObject[] requestedOrderedObjects = new MyObject[results.size];
int i = 0;
foreach(String result: results) {
requestedOrderedObjects[i++] = MyObject.loadFromString(result);
}
return requestedOrderedObjects;
Thank you for any help.
Order is preserved, check the type of Set jedis returns: it is indeed a SortedSet and it is ordered. You are right: the API doesn't give you the hint it is ordered, but you should not be afraid: it works fine, or all my apps would have incredible bugs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With