cytec/zend3-cache-predis

此包已被废弃,不再维护。作者建议使用cytec/laminas-cache-predis包代替。

支持标签的Redis适配器,适用于Zend Framework 3

0.0.6 2019-02-20 10:09 UTC

This package is auto-updated.

Last update: 2020-03-06 11:20:44 UTC


README

支持标签的Redis适配器,适用于Zend Framework 3

安装

composer require cytec/zend3-cache-predis

配置

在你的配置文件中(例如config/autoload/global.php)添加以下内容:

...
'caches' => [
    'AppCache' => [
        'plugins' => ['serializer'],
        'adapter' => [
            'name' => 'Cytec\Cache\Storage\Adapter\Predis',
            'options' => [
                'ttl' => 600,
                'predis_client_connections' => [
                    'host' => '127.0.0.1',
                    'port' => 6379,
                ],
                'predis_client_options' => [
                    'profile' => '2.4',
                    'prefix'  => 'ns:'
                ]
            ],
        ],
    ],
]
...

predis_client_connections选项在创建Predis客户端时直接作为第一个参数传递,而predis_client_options作为第二个参数

$client = new Predis\Client($predis_client_connections, $predis_client_options);

有关更多信息,请参阅Predis文档中的连接参数客户端选项

然后您可以通过服务管理器获取缓存

$cache = $this->getServiceManager()->get('AppCache');
$cache->setItem($key, $value);