Major Issue: iterators that uses SCAN/SSCAN/HSCAN command are not using the same node
Since the fact that keys/Sets/Hashes in redis does not guarantee the order of the elements within, iterators should stick to the same node when iteration was first started, to avoid duplicate and/or missing items.
For example, when you have a Set "A" in master node contains:
- "1"
- "2"
- "3"
- "4"
- "5"
- "6"
- "7"
- "8"
- "9"
- "10"
- "11"
- "12" ...
a slave node could have it in a completely different ordering:
- "8"
- "2"
- "7"
- "3"
- "9"
- "1"
- "4"
- "6"
- "5"
- "10"
- "11"
- "12" ...
Obviously, the running the command SSCAN "A" 0 on master, the result is going to be different to the one from the slave. Further cursor call SSCAN "A" n, could also be different.
The problem is, under the default setting, SentinelConnectionManager uses the RoundRobinBalancer which is utilised to read from both master and slave nodes, and when you have a for loop like this:
for (String i : redisson.<String>getSet("A")) {
System.out.println(i);
}
The output could contain duplicate/missing item(s), and the results could be different each time you run it.
Hi,
It is perfectly understood the set ordering is not guaranteed, however what it does guarantee are items in a set are unique and during an iteration each item in the set is executed once and once only.
Due to the characteristics of the way redis slaves replicates a set from their master. The only way to ensure iteration guarantee is to execute it with only one node.
PS: I really admire the work you have done in this project. It is exactly the feature that I was hopping to find when I started to use redis two years ago, and you have made my dream come true. So thank you very much.
-- Rui Gu Sent with Airmail
On 31 August 2015 at 07:35:09, Nikita Koksharov ([email protected]) wrote:
But the set ordering is not guaranteed, you should use list object in that case
— Reply to this email directly or view it on GitHub.
@jackygurui now i catched your idea! will fix it
fixed. please check