Skip to content

gree/master-slave-redis

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published