3

So, Redis specify the zrange (and related sorted set commands) as an ORDERED set of results (a list without duplicates perhaps?).

Why then the zrange (and related APIs) on Jedis (Official and Recommended REDIS client) return a Set??? Which has, by definition, no concept of ordering?

That is a direct violation of the semantics of the redis operations.

This is the zrange jedis 2.0.0 implementation:


  public Set<byte[]> zrange(final byte[] key, final int start, final int end) {
        checkIsInMulti();
        client.zrange(key, start, end);
        final List<byte[]> members = client.getBinaryMultiBulkReply();
        return new LinkedHashSet<byte[]>(members);
    } 

Jedis contributors, are you planning to fix it?

  • This might be more appropriate as a bug on the Redis project? I'm not sure there's much we can do about it here. – Rob Hruska Dec 20 '11 at 16:04
  • 2
    At first I thought it was another SW:TOR addon question. – corsiKa Dec 20 '11 at 16:07
  • Sure Rob, but I also want to trigger some discussion and some thinking on the people involved with, or, planning to use Jedis, since this not a bug, this is a very serious conceptual issue. – David Costa Faidella Dec 20 '11 at 16:10
  • (s/Redis/Jedis in my previous comment) – Rob Hruska Dec 20 '11 at 16:24
  • @DavidCostaFaidella - I do share your concern. However, SO's Q&A format doesn't lend itself well to discussion; rather, it's more suited for concrete questions that are answerable. At this point, your only question is asking if someone's planning to fix it, which is rather open-ended. It might be more suitable to ask if there's a way to work around it, or to guarantee the ordering? – Rob Hruska Dec 20 '11 at 16:27
  • @DavidCostaFaidella - And don't get me wrong, I'm on your side. The Jedis API should definitely align with Redis behavior. I just feel this might be better-addressed elsewhere. – Rob Hruska Dec 20 '11 at 16:27
  • I already opened an issue on Jedis. The kind of thinking I wanted to trigger has already been higlighted by Eric Hauser below. Conceptual mismatches are the worst enemy of development. – David Costa Faidella Dec 20 '11 at 16:35
  • I don't really see the issue here; ok it could have been typed a bit more concise, but the library still allows you to retrieve the result in the right order, so there is no problem using it. I agree it would be nicer if you can see from the type that elements are ordered, but it's not the end of the world. – The Nail Jan 09 '12 at 22:12
  • If you don't see the issue it might be because you are not using it properly or you don't fully understand interface usage. A Set does not specify ordering. – David Costa Faidella Jan 23 '12 at 12:10

2 Answers2

1

A LinkedHashSet is an ordered set. The API should probably be changed to reflect that explicitly or just return a list.

This conversation is better suited for the mailing list as opposed to SO.

Eric Hauser
  • 5,551
  • 3
  • 26
  • 29
  • That's true, but the method signature ought to specify `LinkedHashSet` as its return type to A) indicate that it *is* returning an ordered set, and B) so clients don't have to cast it or convert it to something to guarantee its ordering. – Rob Hruska Dec 20 '11 at 16:23
  • 1
    That is precisely my point Rob. If I need to look at the underlying implementation of Jedis to understand the semantics of Jedis, Jedis is not very well thought through and it's reliability questionable. @Eric, since it returns a Set, no ordering is guaranteed. – David Costa Faidella Dec 20 '11 at 16:30
  • @DavidCostaFaidella - We're on the same page here; I was simply reiterating your concern from the question w.r.t. Eric's answer :) - You mentioned that you opened an issue; this would be one potential solution. – Rob Hruska Dec 20 '11 at 16:43
  • I hit enter early. Please see the rest of my response. – Eric Hauser Dec 20 '11 at 16:45
  • Actually, redis' documentation says "Multi-bulk reply: **list** of elements in the specified range (optionally with their scores)." – Ivo Dec 22 '11 at 01:13
1

In version 2.2.0 it will be returning SorteSet, according to https://github.com/xetorthio/jedis/issues/244

Ivo
  • 8,172
  • 5
  • 27
  • 42