Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite85dcab

Browse files
committed
[Cache] Use options from Memcached DSN
1 parent481e31c commite85dcab

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

‎src/Symfony/Component/Cache/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* added PruneableInterface so PSR-6 or PSR-16 cache implementations can declare support for manual stale cache pruning
88
* added FilesystemTrait::prune() and PhpFilesTrait::prune() implementations
9+
* added Using options from Memcached DSN
910
* now FilesystemAdapter, PhpFilesAdapter, FilesystemCache, and PhpFilesCache implement PruneableInterface and support
1011
manual stale cache pruning
1112

‎src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,28 @@ public function provideServersSetting()
162162
);
163163
}
164164
}
165+
166+
/**
167+
* @dataProvider provideDSNWithOptions
168+
*/
169+
publicfunctiontestDSNWithOptions($dsn,array$options)
170+
{
171+
$client = MemcachedAdapter::createConnection($dsn);
172+
173+
foreach ($optionsas$option =>$expect) {
174+
$this->assertSame($expect,$client->getOption($option));
175+
}
176+
}
177+
178+
publicfunctionprovideDSNWithOptions()
179+
{
180+
yieldarray(
181+
'memcached://localhost:11222?send_timeout=10',
182+
array(\Memcached::OPT_SEND_TIMEOUT =>10),
183+
);
184+
yieldarray(
185+
'memcached://localhost:11222?socket_recv_size=1&socket_send_size=2',
186+
array(\Memcached::OPT_SOCKET_RECV_SIZE =>1, \Memcached::OPT_SOCKET_SEND_SIZE =>2),
187+
);
188+
}
165189
}

‎src/Symfony/Component/Cache/Traits/MemcachedTrait.php‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,6 @@ public static function createConnection($servers, array $options = array())
8383
$client =new \Memcached($options['persistent_id']);
8484
$username =$options['username'];
8585
$password =$options['password'];
86-
unset($options['persistent_id'],$options['username'],$options['password']);
87-
$options =array_change_key_case($options,CASE_UPPER);
88-
89-
// set client's options
90-
$client->setOption(\Memcached::OPT_BINARY_PROTOCOL,true);
91-
$client->setOption(\Memcached::OPT_NO_BLOCK,true);
92-
if (!array_key_exists('LIBKETAMA_COMPATIBLE',$options) && !array_key_exists(\Memcached::OPT_LIBKETAMA_COMPATIBLE,$options)) {
93-
$client->setOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE,true);
94-
}
95-
foreach ($optionsas$name =>$value) {
96-
if (is_int($name)) {
97-
continue;
98-
}
99-
if ('HASH' ===$name ||'SERIALIZER' ===$name ||'DISTRIBUTION' ===$name) {
100-
$value =constant('Memcached::'.$name.'_'.strtoupper($value));
101-
}
102-
$opt =constant('Memcached::OPT_'.$name);
103-
104-
unset($options[$name]);
105-
$options[$opt] =$value;
106-
}
107-
$client->setOptions($options);
10886

10987
// parse any DSN in $servers
11088
foreach ($serversas$i =>$dsn) {
@@ -139,11 +117,34 @@ public static function createConnection($servers, array $options = array())
139117
if (isset($params['query'])) {
140118
parse_str($params['query'],$query);
141119
$params +=$query;
120+
$options +=$query;
142121
}
143122

144123
$servers[$i] =array($params['host'],$params['port'],$params['weight']);
145124
}
146125

126+
// set client's options
127+
unset($options['persistent_id'],$options['username'],$options['password'],$options['weight']);
128+
$options =array_change_key_case($options,CASE_UPPER);
129+
$client->setOption(\Memcached::OPT_BINARY_PROTOCOL,true);
130+
$client->setOption(\Memcached::OPT_NO_BLOCK,true);
131+
if (!array_key_exists('LIBKETAMA_COMPATIBLE',$options) && !array_key_exists(\Memcached::OPT_LIBKETAMA_COMPATIBLE,$options)) {
132+
$client->setOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE,true);
133+
}
134+
foreach ($optionsas$name =>$value) {
135+
if (is_int($name)) {
136+
continue;
137+
}
138+
if ('HASH' ===$name ||'SERIALIZER' ===$name ||'DISTRIBUTION' ===$name) {
139+
$value =constant('Memcached::'.$name.'_'.strtoupper($value));
140+
}
141+
$opt =constant('Memcached::OPT_'.$name);
142+
143+
unset($options[$name]);
144+
$options[$opt] =$value;
145+
}
146+
$client->setOptions($options);
147+
147148
// set client's servers, taking care of persistent connections
148149
if (!$client->isPristine()) {
149150
$oldServers =array();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp