Search code examples
redisredisson

After RedissonClient.getSet("my-set").size() returns a number, why does the set appear to be empty until next run?


I have a set of strings stored in Redis via Redisson. When I use Redisson to get the set, if I call size() on the set (which returns a positive integer that indicates its size, and thus indicating that there are items in the set), and then (afterward) attempt to get an iterator and read from the set, it now appears to contain zero elements. If I stop my application, and then restart it, and if I skip getting the size of the set, and only get the iterator, then I can iterate through the data. I have tried getting the set at application startup, and keeping the reference to use throughout the execution, and I have also tried using the client to get the set each time, but the behavior is the same with both approaches.

So how can I get the cardinality of the set, and then get an iterator to read through the set?


Solution

  • So, for some reason, I decided to configure my client in single server mode, and the operations worked the way I expected them to work. I could get the cardinality of the set, then iterate through the set without any problem. So there must be some configuration problems with the slave nodes. But what I would like to know is why it consistently works the first time and consistently fails the next time. I.e., I can always get the set size first, or I can always iterate over the set first, and then the next operation always implies that the set is empty. So, I understand that improperly configured slave nodes would cause problems, but it is strange that it behaves so consistently when things go wrong.