The pubsub node will be set according to the passed node, host and port When none of the node, host, or port are specified - the node is set to None and will be determined by the keyslot of the channel in the first command to be executed. RedisClusterExceptio
(self, cluster, node=None, host=None, port=None)
| 2854 | ) |
| 2855 | |
| 2856 | def set_pubsub_node(self, cluster, node=None, host=None, port=None): |
| 2857 | """ |
| 2858 | The pubsub node will be set according to the passed node, host and port |
| 2859 | When none of the node, host, or port are specified - the node is set |
| 2860 | to None and will be determined by the keyslot of the channel in the |
| 2861 | first command to be executed. |
| 2862 | RedisClusterException will be thrown if the passed node does not exist |
| 2863 | in the cluster. |
| 2864 | If host is passed without port, or vice versa, a DataError will be |
| 2865 | thrown. |
| 2866 | :type cluster: RedisCluster |
| 2867 | :type node: ClusterNode |
| 2868 | :type host: str |
| 2869 | :type port: int |
| 2870 | """ |
| 2871 | if node is not None: |
| 2872 | # node is passed by the user |
| 2873 | self._raise_on_invalid_node(cluster, node, node.host, node.port) |
| 2874 | pubsub_node = node |
| 2875 | elif host is not None and port is not None: |
| 2876 | # host and port passed by the user |
| 2877 | node = cluster.get_node(host=host, port=port) |
| 2878 | self._raise_on_invalid_node(cluster, node, host, port) |
| 2879 | pubsub_node = node |
| 2880 | elif any([host, port]) is True: |
| 2881 | # only 'host' or 'port' passed |
| 2882 | raise DataError("Passing a host requires passing a port, and vice versa") |
| 2883 | else: |
| 2884 | # nothing passed by the user. set node to None |
| 2885 | pubsub_node = None |
| 2886 | |
| 2887 | self.node = pubsub_node |
| 2888 | |
| 2889 | def get_pubsub_node(self): |
| 2890 | """ |
no test coverage detected