diff --git a/aredis/client.py b/aredis/client.py index 91973db5..2b6a8efc 100644 --- a/aredis/client.py +++ b/aredis/client.py @@ -400,7 +400,7 @@ async def execute_command(self, *args, **kwargs): # MOVED node = self.connection_pool.get_master_node_by_slot(slot) else: - node = self.connection_pool.get_node_by_slot(slot) + node = self.connection_pool.get_node_by_slot(slot, command) r = self.connection_pool.get_connection_by_node(node) try: diff --git a/aredis/pool.py b/aredis/pool.py index 1fbb2cc7..e56a57b0 100644 --- a/aredis/pool.py +++ b/aredis/pool.py @@ -494,7 +494,8 @@ def get_connection_by_node(self, node): def get_master_node_by_slot(self, slot): return self.nodes.slots[slot][0] - def get_node_by_slot(self, slot): - if self.readonly: + def get_node_by_slot(self, slot, command=None): + #prevent movederr exception, optimized read lookup speed + if self.readonly and command in ["GET", "GETBIT", "HGETALL", "HMGET", "HLEN", "LLEN", "LINDEX", "MGET"]: return random.choice(self.nodes.slots[slot]) return self.get_master_node_by_slot(slot)