It could be extremely useful to have LIMIT option for the following commands ZInterStore SInter/SInterStore

For convenience I'd also suggest to add this option to other set commands, such as ZUnionStore SDiff/SDiffStore, SUnion/SUnionStore

With this option command would work as usual but stop right away as output reached LIMIT elements This can be useful in various scenarios and currently there is no way to implement such logic in resource-efficient way.

I often find myself in a situation when I just need a single element from intersection(any of them) but I still have to perform full intersection and then discard all other elements which is quickly becomes a waste as cardinality of set grows

Ideas?

Comment From: mgravell

The main thing that occurs to me is that there would be no defined/predictable behavior here, in terms of sets being unsorted - all you could say is that you got "some" data (well, n records, but no specific definition of which). That may be sufficient, I don't know; but it is a complication and likely cause of confusion.

Comment From: let4be

For sorted sets we could also introduce Order(asc/desc) option - but probably this would be too big complication as redis aims to be simple

Comment From: shaharmor

I could really use this feature as well

Comment From: yoav-steinberg

The main thing that occurs to me is that there would be no defined/predictable behavior here...

Agree. Another thing that comes to mind is how useful this would be in case you want to get the next batch of elements after you reach the first limit. @itamarhaber what do you think?

Comment From: avaziman

I could use this with sorted sets too.

That may be sufficient, I don't know; but it is a complication and likely cause of confusion.

Agree that it could be more confusing than beneficial for unordered sets.

However, for sorted sets, it would be highly beneficial because retrieving the next elements wouldn't be a problem with the consistent order.

Another thing to consider is that sorted set operations can be used on unordered sets as well, so some behavior needs to be defined when the sorted set isn't the one with the smallest cardinality, since ignoring this will lead to inconsistent order as with unordered set operations.

For sorted sets we could also introduce Order(asc/desc) option - but probably this would be too big complication as redis aims to be simple

Perhaps a negative offset number can be used as with list operations to keep it simple?