Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get nodes from cluster client #991

Open
danprueitt opened this issue Nov 23, 2023 · 3 comments
Open

Get nodes from cluster client #991

danprueitt opened this issue Nov 23, 2023 · 3 comments

Comments

@danprueitt
Copy link

I want to scan match each node in my redis cluster. As far as i can see, the routing for scan is random and there are no exposed functions I'm aware of that give the ability to change the routing to all read replicas or all masters exposed to the user.

My next thought was to iterate over the connections in my cluster and perform the operation on each node, but I can't see a get_connections or similar command to iterate over.

I do have the initial connection strings that i could use to open a new connection to each node manually but I want to check I'm not missing anything. If I'm not, would it make sense to expose routing or be able to iterate over the connections to each node?

@nihohit
Copy link
Contributor

nihohit commented Nov 23, 2023

Routing will be exposed in the async cluster in the next release (

pub async fn route_command(&mut self, cmd: &Cmd, routing: RoutingInfo) -> RedisResult<Value> {
). If you want to contribute exposed routing to the sync cluster, that will be very much appreciated.

As for being able to iterate over the connections of each node - I believe that will be simple in the sync cluster connection, but not so simple in the async one, due to its disjoint structure. Again, contributions will be very much appreciated.
In any case you can get info on the structure of the cluster using CLUSTER NODES/SLOTS/SHARDS.

@nihohit
Copy link
Contributor

nihohit commented Mar 12, 2024

@danprueitt has this issue been fully or partially mitigated in 0.25.0?

@joachimbulow
Copy link
Contributor

Not exactly a solution to this, but anyway, for reference, I was able to make something work by hashtagging my keys and obtaining a RoutingInfo like so:

  let routing_info = RoutingInfo::SingleNode(SpecificNode(Route::new(
            get_slot("{my_pattern}".as_bytes()),
            ReplicaOptional,
        )));

(Imports are from the cluster_routing.rs)

And then using that with the newly exposed route_command function to call my function specifically to the correct node:

 let foo_cmd = redis::cmd("SCAN")
            .cursor_arg(0)
            .arg("MATCH")
            .arg("{my_pattern}:*")
            .arg("COUNT")
            .arg(1000)
            .to_owned();

        let my_res = my_conn.route_command(&foo_cmd, routing_info).await?;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants