0

I've a Redis cluster v7.x with 3 masters, each having 1 slave.

A function myFunction written in Lua scripting is loaded in all the 3 masters. The function doesn't need any keys, but some args.

Is it possible for the function to access a data structure, e.g. a SortedSet which is stored on another master node?

Alternatively, is it possible to direct the call to that node which hosts the targeted sorted set? I'm using ioredis library for node.js. The redis cluster IPs are not exposed to the client, but only a service name configured through the Kubernetes.

This is required because the call coming from various client might be redirected to any node and the function definition present there needs to access a specific data structure which may not be on the same node which is handling the client request.

1 Answer 1

1

A function can only access keys on the shard it was called on. If you try to access a key on a different shard you'll either get a MOVED or a CROSSSLOT error.

The function doesn't need any keys, but some args.

This is contradictory in the context of your question, you have a sorted set you need to access. That is your key argument. With each call to FCALL you specify the keys that your function needs to access, that sorted set would be the key. By specifying your keys you give your client what it needs to direct your function call to the correct shard. If you only have the one sorted set you need to access, then your client should just direct everything for you without any other intervention.

If however you want to access multiple keys in your function you must ensure they are in the same hash-slot so that you will not encounter cross-slot issues. See Hash Tags in the redis cluster spec, that explains how to ensure you are scoping your key-names correctly so you guarantee they are on the right shard.

Sign up to request clarification or add additional context in comments.

5 Comments

My function doesn't need keys, but several args. Updating my question with more info. How would client take the responsibility to redirect to a specific master node? The client only knows a servicename offered by the Kubernetes cluster.
The sorted set you need to access is your key.
The sorted set is a fixed named and it's hardcoded within the function definition. It's not passed through fcall. My calls is like fcall myFunction 0 arg1 arg2
Right, so THAT is the problem. you should not be accessing keys in redis that you do not specify as a key in FCALL, for exactly this reason, see redis.io/docs/interact/programmability/functions-intro/…
It worked with sorted set being passed as a key. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.