Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I specify full key names when using Lua in Redis Cluster, or can I just pass the hashtags?

Tags:

redis

lua

I have Lua script which I'm considering migrating to Redis Cluster

Should I specify full key names when call eval? Or can I get away just by specifying hashtags?

For example, I wish to pass only {UNIQUE_HASH_TAG} instead of {UNIQUE_HASH_TAG}/key1, {UNIQUE_HASH_TAG}/key2 ... etc

I have lots of keys, and logic is pretty complicated - sometimes I end up generating key names dynamically but within the same hash tag.

Would I violate some specifications by passing just hash tags instead of key names?

like image 467
let4be Avatar asked Jan 12 '16 10:01

let4be


1 Answers

Should I specify full key names

That's the recommended practice.

Would I violate some specifications

No, the specs do not state that key names need to be explicitly passed. The KEYS/ARGV mechanism was put in place in preparation for the cluster but before the cluster actually came to be. At that time, hash tags were not a part of the cluster's design so the recommendation was to avoid hard-coding/dynamically generating key names in scripts as there's no assurance they'll be in the same cluster hash slot.

Your approach is perfectly valid and would work as expected. I do want to emphasize that this only makes sense if you're managing a lot of the so-called {UNIQUE_HASH_TAG}s - otherwise you'll be hitting just a few slots which could become a scalability challenge.

EDIT: All that said, you really should always explicitly pass the key names to the script rather than tricking. While this isn't currently blocked, this unspecified behavior may change in the future and result in breakage of your code.

like image 185
Itamar Haber Avatar answered Oct 06 '22 06:10

Itamar Haber