def test_max_connections(self):
        pool = cluster_pool_from_config({
            "rediscluster.url": f"redis://{redis_endpoint}/0",
            "rediscluster.max_connections": "300",
        })

        self.assertEqual(pool.max_connections, 300)
    def test_timeouts(self):
        pool = cluster_pool_from_config({
            "rediscluster.url": f"redis://{redis_endpoint}/0",
            "rediscluster.timeout": "30 seconds",
        })

        self.assertEqual(pool.timeout, 30)
    def test_basic_url(self):
        pool = cluster_pool_from_config(
            {"rediscluster.url": f"redis://{redis_endpoint}/0"})

        self.assertEqual(pool.nodes.startup_nodes[0]["host"],
                         "redis-cluster-node")
        self.assertEqual(pool.nodes.startup_nodes[0]["port"], "7000")
    def test_only_primary_available(self):
        pool = cluster_pool_from_config(
            {"rediscluster.url": f"redis://{redis_endpoint}/0"})
        node_list = [
            pool.get_node_by_slot(slot=1, read_command=False)
            for _ in range(0, 100)
        ]

        # The primary is on port 7000 so that's the only port we expect to see
        self.assertTrue(all(node["port"] == 7000 for node in node_list))
    def test_read_from_replicas(self):
        pool = cluster_pool_from_config(
            {"rediscluster.url": f"redis://{redis_endpoint}/0"})

        node_list = [
            pool.get_node_by_slot(slot=1, read_command=True)
            for _ in range(0, 100)
        ]

        # Both replicas and primary are available, so we expect to see some non-primaries here
        self.assertTrue(any(node["port"] != 7000 for node in node_list))
 def test_alternate_prefix(self):
     pool = cluster_pool_from_config(
         {"noodle.url": f"redis://{redis_endpoint}/0"}, prefix="noodle.")
     self.assertEqual(pool.nodes.startup_nodes[0]["host"],
                      "redis-cluster-node")
     self.assertEqual(pool.nodes.startup_nodes[0]["port"], "7000")
    def test_kwargs_passthrough(self):
        pool = cluster_pool_from_config(
            {"rediscluster.url": f"redis://{redis_endpoint}/0"},
            example="present")

        self.assertEqual(pool.connection_kwargs["example"], "present")
    def test_max_connections_default(self):
        # https://github.com/Grokzen/redis-py-cluster/issues/435
        pool = cluster_pool_from_config(
            {"rediscluster.url": f"redis://{redis_endpoint}/0"})

        self.assertEqual(pool.max_connections, 50)
 def test_empty_config(self):
     with self.assertRaises(ConfigurationError):
         cluster_pool_from_config({})