Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    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")
Пример #4
0
    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))
Пример #5
0
    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))
Пример #6
0
 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")
Пример #7
0
    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")
Пример #8
0
    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)
Пример #9
0
 def test_empty_config(self):
     with self.assertRaises(ConfigurationError):
         cluster_pool_from_config({})