Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Memcached adapter bind #136

Merged
merged 7 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"ray/aop": "^2.10",
"ray/di": "^2.13.1",
"ray/psr-cache-module": "^1.3.2",
"ray/psr-cache-module": "^1.3.3",
"symfony/cache": "^5.3 || ^6.0",
"symfony/cache-contracts": "^2.4 || ^3.0"
},
Expand Down
3 changes: 2 additions & 1 deletion src/StorageMemcachedModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Psr\Cache\CacheItemPoolInterface;
use Ray\Di\AbstractModule;
use Ray\PsrCacheModule\Annotation\CacheNamespace;
use Ray\PsrCacheModule\MemcachedAdapter;
koriym marked this conversation as resolved.
Show resolved Hide resolved
use Ray\PsrCacheModule\Psr6MemcachedModule;
use Symfony\Component\Cache\Adapter\MemcachedAdapter;

final class StorageMemcachedModule extends AbstractModule
{
Expand All @@ -29,6 +29,7 @@ protected function configure(): void
$this->install(new Psr6MemcachedModule($this->servers));
$this->bind(CacheItemPoolInterface::class)->annotatedWith(EtagPool::class)->toConstructor(MemcachedAdapter::class, [
'namespace' => CacheNamespace::class,
'clientProvider' => 'memcached',
]);
}
}
3 changes: 2 additions & 1 deletion src/StorageRedisMemcachedModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use Ray\Di\AbstractModule;
use Ray\PsrCacheModule\Annotation\CacheNamespace;
use Ray\PsrCacheModule\Annotation\MemcacheConfig;
use Ray\PsrCacheModule\MemcachedAdapter;
koriym marked this conversation as resolved.
Show resolved Hide resolved
use Ray\PsrCacheModule\MemcachedProvider;
use Ray\PsrCacheModule\Psr6RedisModule;
use Symfony\Component\Cache\Adapter\MemcachedAdapter;

use function array_map;
use function explode;
Expand Down Expand Up @@ -44,6 +44,7 @@ protected function configure(): void
$this->install(new Psr6RedisModule($this->redisServer));
$this->bind(CacheItemPoolInterface::class)->annotatedWith(EtagPool::class)->toConstructor(MemcachedAdapter::class, [
'namespace' => CacheNamespace::class,
'clientProvider' => 'memcached',
]);
$this->bind()->annotatedWith(MemcacheConfig::class)->toInstance($this->memcacheServer);
$this->bind(Memcached::class)->toProvider(MemcachedProvider::class);
Expand Down
4 changes: 2 additions & 2 deletions tests-pecl-ext/StorageMemcachedModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
use Psr\Cache\CacheItemPoolInterface;
use Ray\Di\Injector;
use Ray\PsrCacheModule\Annotation\Shared;
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
use Ray\PsrCacheModule\MemcachedAdapter;

class StorageMemcachedModuleTest extends TestCase
{
public function testNew()
public function testNew(): void
{
// @see http://php.net/manual/en/memcached.addservers.php
$servers = 'mem1.domain.com:11211:33,mem2.domain.com:11211:67';
Expand Down
20 changes: 10 additions & 10 deletions tests-pecl-ext/StorageRedisModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,47 @@
use Psr\Cache\CacheItemPoolInterface;
use Ray\Di\Injector;
use Ray\PsrCacheModule\Annotation\Shared;
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Ray\PsrCacheModule\MemcachedAdapter;
use Ray\PsrCacheModule\RedisAdapter;
use Symfony\Component\Process\Process;

use function getenv;
use function usleep;

class StorageRedisModuleTest extends TestCase
{
/**
* @var Process
*/
/** @var Process */
private static $process;

/** @var string */
private $server;

public static function setUpBeforeClass() : void
public static function setUpBeforeClass(): void
{
self::$process = new Process(['redis-server']);
self::$process->disableOutput();
self::$process->start();
usleep(1000000); //wait for server to get going
}

public static function tearDownAfterClass() : void
public static function tearDownAfterClass(): void
{
self::$process->stop(1);
}

protected function setUp() : void
protected function setUp(): void
{
$this->server = getenv('REDIS_SERVER') ? getenv('REDIS_SERVER') : 'localhost:6379';
}

public function testNew()
public function testNew(): void
{
// @see http://php.net/manual/en/memcached.addservers.php
$cache = (new Injector(new StorageRedisModule($this->server), __DIR__ . '/tmp'))->getInstance(CacheItemPoolInterface::class, Shared::class);
$this->assertInstanceOf(RedisAdapter::class, $cache);
}

public function testNewRedisMemchache()
public function testNewRedisMemcached(): void
{
// @see http://php.net/manual/en/memcached.addservers.php
$memcacheServers = 'mem1.domain.com:11211:33,mem2.domain.com:11211:67';
Expand Down
Loading