Does Redis guarantee mget return order?
Asked Answered
P

2

8

Given this simplistic block:

mget object:1 object:2 object:3

Does redis guarantee that the return order will always be [object:1,object:2,object:3]?

I'm using the standard ruby redis client (v3.3.0), so it should return exactly what redis does and not affect anything.

Phaidra answered 29/11, 2016 at 15:39 Comment(0)
G
5

Although the documentation isn't explicit about this, I think it does guarantee the order. It'd be a very useless command if it didn't.

Garfield answered 29/11, 2016 at 15:46 Comment(3)
I did some relatively informal scripting to check results and got the expected results back, but you're right about the documentation not being explicit about it, which is why I posted up here.Phaidra
When in doubt, check the source. github.com/antirez/redis/blob/…Militarist
Judging by the for loop in the source code I would say YES it ALWAYS comes back in the same order.Suppository
A
-1

As Redis Cluster is widely used, I have to make a note here that:

  • mget does guarantee order in Redis Standalone mode like @Sergio's answer said

But in Redis Cluster, it's the client library that determines the order of the result. And apparently some of them do not make the guarantee, eg, vert.x redis client. From the source code:

    addReducer(MGET, list -> {
      int total = 0;
      for (Response resp : list) {
        total += resp.size();
      }

      MultiType multi = MultiType.create(total, false);
      for (Response resp : list) {
        for (Response child : resp) {
          multi.add(child);
        }
      }

      return multi;
    });

We can see it simply merges mget result from every node and thus no guarantee on order is provided here.

Alyose answered 12/5, 2023 at 15:24 Comment(1)
I don't know why downvoteAlyose

© 2022 - 2024 — McMap. All rights reserved.