Ability to call keys in specific key slot
creker opened this issue · comments
Right now keys
command is not specifying any key slot and executed on an arbitrary node. It would be useful if rueidis would allow locking keys
to specific key slot.
My use-case is that I want to list all keys that are guaranteed to land in the same key slot. For example, given the following keys
foo{a}:1
foo{b}:2
foo{b}:3
foo{c}:4
foo{d}:5
I want to execute keys foo{b}:*
and expect it to return foo{b}:2
and foo{b}:3
. In order to do that now I have to send that command to all nodes. That seems wasteful.
One way this could be implemented is to add new method to internal/cmds/Keys
or internal/cmds/KeysPattern
that would tell rueidis to use the given pattern in key slot calculation. For example, for Keys
it could be something like PatternKeySlot
that would do the same thing as Pattern
but would also calculate key slot. For KeysPattern
it could be KeySlot
that would use previously specified pattern to calculate key slot.
This is a good idea and there might be other commands that need this as well.
So, I think we can add a SetSlot(...)
function to the Completed
struct. For example:
cmd := client.B().Keys().Pattern("foo{a}:1").Build().SetSlot("a")