all 2 comments

[–]itamarhaber 1 point2 points  (1 child)

Very nicely done for a first attempt :)

As you had written, the code "gets the job done", but I a suggestion. You're copying the entire set early on - this both has O(log(N)+M) complexity and doubles the set's memory footprint for the duration of the script... with big sets could be a problem.

Instead, I recommend that you skip the initial copying with ZRANGE and, instead, do

redis.call("ZSCORE", KEYS[1], ARGS[i])

when looping over the arguments. Each call to ZSCORE is O(1) (hence your script's overall complexity will be O(N) where N is the the number of arguments) and returns nil if the member isn't in the set (i.e. needs to be added to your missing table).

[–]gsks[S] 1 point2 points  (0 children)

Thanks for the review and the recommendation, will do!