7

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?

Sled
  • 18,541
  • 27
  • 119
  • 168
let4be
  • 1,048
  • 11
  • 30

1 Answers1

4

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.

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
  • This would make my migration totally impossible, unfortunately I can't avoid creating keys on the fly(if we had nested data types, like set inside set, this wouldn't be needed), but when I do so I always do it within the hashtag... – let4be Jan 14 '16 at 10:05
  • 1
    For my task I need only certain features from redis cluster, for example ability to re-balance my data between nodes. As an alternative I'm considering implementing this manually via Lua + `Move` command(mark data set as unavailable, serialize data set inside a single key, atomically move to another instance, deserialize, mark as available on a new instance, remove original data set) - but this looks like reinventing the wheel – let4be Jan 14 '16 at 10:16