redis / lettuce

Advanced Java Redis client for thread-safe sync, async, and reactive usage. Supports Cluster, Sentinel, Pipelining, and codecs.
https://lettuce.io
MIT License
5.35k stars 958 forks source link

Support Setting READ Intent for unknown commands when using MasterReplica connection #2291

Open rikostave1234 opened 1 year ago

rikostave1234 commented 1 year ago

Feature Request

Problem

We would like to use RediSearch in combination with a Master/Replica setup in order to be able to perform search operations against multiple replicated nodes at the same time. Our Spring Boot application is using Spring Data Redis with a RedisStandaloneConfiguration to connect to our master redis node. It seems that Master and Replica nodes are discovered correctly as e.g. scan commands are executed against Replica nodes. However, all RediSearch commands, e.g. 'FT.SEARCH' end up being executed on a connection with Intent.WRITE, which always points to the Master node. That is because the ReadonlyCommands enum does not contain commands from the RediSearch module and thus interprets them as write requests.

Possible solutions

We have two possible solutions in mind:

1.) Allow registration of custom readonly commands

2.) Allow to manually set the READ/WRITE intent on a connection.

The second approach is similar to what has been implemented for cluster connections, see #2095 The first approach might be a more general solution as it would allow the use of the Commands interface but seems to require a larger refactoring.

mp911de commented 1 year ago

Initially, the read intent was a good idea to begin with but over time and with the growth of commands, we would need a strategy interface that is able to determine whether a command is a read or a write command.