necromant2005/tt-ssdb

SSDB 缓存适配器,适用于 ZF2

1.2.0 2016-06-11 00:51 UTC

This package is auto-updated.

Last update: 2024-08-29 04:36:58 UTC


README

版本 2.0.1 由 Rostislav Mykhajliw 创建

Build Status

简介

支持主/从复制的 SSDB 适配器

特性 / 目标

  • 标准接口 zf2 Zend\Cache\Storage\Adapter
  • 支持主/从复制
  • 支持服务器读取权重
  • 支持故障转移

安装

主要设置

使用 composer

  1. 将以下内容添加到您的 composer.json 中
"require": {
    "necromant2005/tt-ssdb": "1.*",
}
  1. 现在运行以下命令让 composer 下载 TweeSSDB:
$ php composer.phar update

使用方法

配置 1 个主节点和 2 个从节点,由于权重配置,只有 1/5 的读取操作发送到主节点,其余 4/5 发送到从节点。每个从节点接收 2/5 的读取操作。

use TweeSSDB\Cache\Storage\Adapter;

$options = new SSDBOptions(array(
    array('host' => '127.0.0.1', 'port' => 8888, 'weight' => 1, 'type' => 'master'),
    array('host' => '127.0.0.2', 'port' => 8888, 'weight' => 2, 'type' => 'slave'),
    array('host' => '127.0.0.3', 'port' => 8888, 'weight' => 2, 'type' => 'slave'),
));
$adapter = new SSDB($options);

还可以使用多主写入 - 在这种情况下,写入将在所有主节点之间分配(包括读取操作)

use TweeSSDB\Cache\Storage\Adapter;

$options = new SSDBOptions(array(
    array('host' => '127.0.0.1', 'port' => 8888, 'weight' => 1, 'type' => 'master'),
    array('host' => '127.0.0.2', 'port' => 8888, 'weight' => 1, 'type' => 'master'),
    array('host' => '127.0.0.3', 'port' => 8888, 'weight' => 1, 'type' => 'master'),
));
$adapter = new SSDB($options);