Skip to content

Commit

Permalink
Merge pull request #136 from apple-x-co/fix-memcached-adapter-bind
Browse files Browse the repository at this point in the history
Fix Memcached adapter bind
  • Loading branch information
koriym authored May 14, 2024
2 parents b7c0ebd + c94e98c commit 9ef5a2b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
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.4",
"symfony/cache": "^5.3 || ^6.0",
"symfony/cache-contracts": "^2.4 || ^3.0"
},
Expand Down
2 changes: 1 addition & 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;
use Ray\PsrCacheModule\Psr6MemcachedModule;
use Symfony\Component\Cache\Adapter\MemcachedAdapter;

final class StorageMemcachedModule extends AbstractModule
{
Expand Down
4 changes: 3 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;
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,8 +44,10 @@ 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(MemcachedProvider::class);
$this->bind(Memcached::class)->toProvider(MemcachedProvider::class);
}
}
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

0 comments on commit 9ef5a2b

Please sign in to comment.