跳到内容

Couchbase Bucket 缓存适配器

编辑此页

7.1

The CouchbaseBucketAdapter is deprecated since Symfony 7.1, use the CouchbaseCollectionAdapter instead.

此适配器使用一个(或多个)Couchbase 服务器实例在内存中存储值。与 APCu 适配器不同,并且与 Memcached 适配器类似,它不限于当前服务器的共享内存;您可以独立于 PHP 环境存储内容。还可以利用服务器集群来提供冗余和/或故障转移。

警告

要求: 必须安装、激活并运行 Couchbase PHP 扩展以及 Couchbase 服务器才能使用此适配器。此适配器需要版本 2.6 或低于 3.0 的 Couchbase PHP 扩展

此适配器期望将 Couchbase Bucket 实例作为第一个参数传递。命名空间和默认缓存生存期可以选择性地作为第二个和第三个参数传递

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use Symfony\Component\Cache\Adapter\CouchbaseBucketAdapter;

$cache = new CouchbaseBucketAdapter(
    // the client object that sets options and adds the server instance(s)
    $client,

    // the name of bucket
    $bucket,

    // a string prefixed to the keys of the items stored in this cache
    $namespace,

    // the default lifetime (in seconds) for cache items that do not define their
    // own lifetime, with a value 0 causing items to be stored indefinitely
    $defaultLifetime
);

配置连接

createConnection() 辅助方法允许使用数据源名称 (DSN) 或 DSN 数组创建和配置 Couchbase Bucket 类实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use Symfony\Component\Cache\Adapter\CouchbaseBucketAdapter;

// pass a single DSN string to register a single server with the client
$client = CouchbaseBucketAdapter::createConnection(
    'couchbase://127.0.0.1'
    // the DSN can include config options (pass them as a query string):
    // 'couchbase://127.0.0.1:11210?operationTimeout=10'
    // 'couchbase://127.0.0.1:11210?operationTimeout=10&configTimeout=20'
);

// pass an array of DSN strings to register multiple servers with the client
$client = CouchbaseBucketAdapter::createConnection([
    'couchbase://10.0.0.100',
    'couchbase://10.0.0.101',
    'couchbase://10.0.0.102',
    // etc...
]);

// a single DSN can define multiple servers using the following syntax:
// host[hostname-or-IP:port] (where port is optional). Sockets must include a trailing ':'
$client = CouchbaseBucketAdapter::createConnection(
    'couchbase:?host[localhost]&host[localhost:12345]'
);

配置选项

createConnection() 辅助方法还接受一个选项数组作为其第二个参数。 期望的格式是表示选项名称及其各自值的 key => value 对的关联数组

1
2
3
4
5
6
7
8
9
10
11
12
13
use Symfony\Component\Cache\Adapter\CouchbaseBucketAdapter;

$client = CouchbaseBucketAdapter::createConnection(
    // a DSN string or an array of DSN strings
    [],

    // associative array of configuration options
    [
        'username' => 'xxxxxx',
        'password' => 'yyyyyy',
        'configTimeout' => '100',
    ]
);

可用选项

username (类型: string)
连接 CouchbaseCluster 的用户名。
password (类型: string)
连接 CouchbaseCluster 的密码。
operationTimeout (类型: int, 默认值: 2500000)
操作超时(以微秒为单位)是库在操作接收到响应之前等待的最长时间,然后以失败状态调用其回调。
configTimeout (类型: int, 默认值: 5000000)
客户端等待获取初始配置的时间(以微秒为单位)。
configNodeTimeout (类型: int, 默认值: 2000000)
每个节点的配置超时(以微秒为单位)。
viewTimeout (类型: int, 默认值: 75000000)
用于 Couchbase Views API 的 HTTP 请求的 I/O 超时(以微秒为单位)。
httpTimeout (类型: int, 默认值: 75000000)
用于 HTTP 查询(管理 API)的 I/O 超时(以微秒为单位)。
configDelay (类型: int, 默认值: 10000)
配置刷新限制 修改配置错误阈值将被强制设置为其最大值以强制配置刷新之前的时长(以微秒为单位)。
htconfigIdleTimeout (类型: int, 默认值: 4294967295)
HTTP 引导的空闲/持久性(以微秒为单位)。
durabilityInterval (类型: int, 默认值: 100000)
客户端在重复探测给定服务器之间等待的时间(以微秒为单位)。
durabilityTimeout (类型: int, 默认值: 5000000)
客户端花费时间(以微秒为单位)向给定键的 vBucket 主服务器和副本发送重复探测,然后它们被认为未满足持久性要求。

提示

请参考 Couchbase Bucket 扩展的预定义常量文档,以获取有关可用选项的更多信息。

本作品,包括代码示例,根据 Creative Commons BY-SA 3.0 许可协议获得许可。
目录
    版本