Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.
This repository was archived by the owner on Jan 9, 2024. It is now read-only.

readonly mode not execute command on slave node #339

Open
@ididid8

Description

@ididid8

I set readonly_mode=True to test the readonly mode. And print the node which realy execute command. But whether readonly_mode is True or False the node server_type is all master.

from rediscluster import RedisCluster


def main():
    startup_nodes = [{"host": "", "port": ""}]
    rc = RedisCluster(startup_nodes=startup_nodes, decode_responses=True, readonly_mode=True)
    print(rc.set('foo', 'bar'))
    print(rc.get('foo'))

if __name__ == "__main__":
    main()

I print the node in client.py to get node info.

 @clusterdown_wrapper
    def execute_command(self, *args, **kwargs):
        """
        Send a command to a node in the cluster
        """
        ....
            else:
                if self.refresh_table_asap:
                    # MOVED
                    node = self.connection_pool.get_master_node_by_slot(slot)
                else:
                    node = self.connection_pool.get_node_by_slot(slot, self.read_from_replicas and (command in self.READ_COMMANDS))
                    is_read_replica = node['server_type'] == 'slave'
                print(node)
                r = self.connection_pool.get_connection_by_node(node)

        ....

The print is :

{'host': '', 'port': , 'name': '', 'server_type': 'master'}
True
{'host': '', 'port': , 'name': '', 'server_type': 'master'}
bar

I consider is because of the partial get node.

                if self.refresh_table_asap:
                    # MOVED
                    node = self.connection_pool.get_master_node_by_slot(slot)
                else:
                    node = self.connection_pool.get_node_by_slot(slot, self.read_from_replicas and (command in self.READ_COMMANDS))
                    is_read_replica = node['server_type'] == 'slave'
                r = self.connection_pool.get_connection_by_node(node)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions