Skip to content

Latest commit

 

History

History
87 lines (72 loc) · 1.58 KB

README.md

File metadata and controls

87 lines (72 loc) · 1.58 KB

MasterSlaveRedis

Redisのレプリカを使えるようにする。

Usage

$manager = new RedisManager([
    "master" => [
        "host" => "master-host",
    ],
    "slave" => [
        [
            "host" => "slave-host",
        ]
    ]
]);

$manager->getMaster()->set("key", 1); // master-host
$manager->getSlave()->get("key"); // slave-host
$manager = new RedisManager([
    "master" => [
        "host" => "master-host",
    ],
    "slave" => [
    ]
]);

$manager->getMaster()->set("key", 1); // master-host
$manager->getSlave()->get("key"); // master-host, use master
$manager = new RedisManager([
    "master" => [
        "host" => "master-host",
    ],
    "slave" => [
        [
            "host" => "slave1",
        ],
        [
            "host" => "slave2",
        ],
        [
            "host" => "slave3",
        ],
    ]
]);

$manager->getMaster()->set("key", 1); // master-host
$manager->getSlave()->get("key"); // slave1, slave2 or slave3, random choice
$manager = new RedisManager([
    "master" => [
        "host" => "master-host",
        "port" => 6379,  // 指定可能。デフォルトは6379
        "timeout" => 0, // 指定可能。デフォルトは0(無制限)
    ],
    "slave" => [
    ]
]);

$manager->getMaster()->set("key", 1); // master-host
$manager->getSlave()->get("key"); // master-host, use master

Test

docker-compose up -d --scale redis-slave1=4 redis-slave1
docker-compose run --rm phpunit-full

Test design

Feature Small Medium
Server Access No Yes
Logic Yes Yes