antirez / RESP3

RESP protocol V3 repository. Contains the specification, and other related resource
229 stars 41 forks source link

Set replies - unique? #7

Closed stockholmux closed 6 years ago

stockholmux commented 6 years ago

Looking at the set replies, can you have non-unique items?

Example - is this valid?

~3<CR><LF>
+redis<CR><LF>
+redis<CR><LF>
+redis<CR><LF>
antirez commented 6 years ago

That's a good question @stockholmux. Redis will never emit such protocol, however probably better for the client to be resistant to such cases, by avoiding re-adding the same element again. A good example on how that could be potentially useful is if we would reply with a Set reply to SCAN. The command is unable to guarantee unicity, yet the returned keys are not ordered in any way. I'll add a section about it, thanks.

antirez commented 6 years ago

@stockholmux fixed hopefully.

stockholmux commented 6 years ago

Perfect. So, in this case this maps nicely to Javascript sets:

const set1 = new Set();

set1.add(42);
set1.add(42);
set1.add(13);

for (let item of set1) {
  console.log(item);
  // expected output: 42
  // expected output: 13
}

My only concern would be a module that emits a non-unique set.

antirez commented 6 years ago

Yes could happen and better for it to be valid at protocol level. Trivial case: module that emits N random numbers.