mpapec
mpapec

Reputation: 50637

Removing elements from sorted set - ZREM

I'm removing elements with ZREM, however more often than not element is not member of sorted set.

Should I first check with ZSCORE whether element is in set and then proceed with ZREM since former is O(1) and thus faster overall?

Upvotes: 0

Views: 567

Answers (1)

for_stack
for_stack

Reputation: 22906

NO. It makes your code more complicated, and might be slower.

Compared to network RTT (in milliseconds), these two commands run very fast (in microseconds). You can almost ignore the command processing time.

Also, if the element exists, you have to send 2 commands, and get double RTTs. That will be much slower than sending only 1 command.

Yes, you can wrap the logic into a Lua script to avoid the extra RTT. However, that makes it more complicated. Also exchanging values between Lua and C might cost more than the command processing time.

Upvotes: 2

Related Questions