From 510493969100bec67d66292aaf073ed47fdd54f6 Mon Sep 17 00:00:00 2001 From: "akihito.nakano" Date: Sun, 23 Dec 2018 14:41:40 +0900 Subject: [PATCH 1/2] Add test case which reproduces the issue #29 --- tests/Ackintosh/Ganesha/StorageTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Ackintosh/Ganesha/StorageTest.php b/tests/Ackintosh/Ganesha/StorageTest.php index 7472722..eec18f4 100644 --- a/tests/Ackintosh/Ganesha/StorageTest.php +++ b/tests/Ackintosh/Ganesha/StorageTest.php @@ -3,6 +3,7 @@ use Ackintosh\Ganesha; use Ackintosh\Ganesha\Storage\Adapter\Memcached; +use Ackintosh\Ganesha\Storage\Adapter\Redis; class StorageTest extends \PHPUnit_Framework_TestCase { @@ -23,4 +24,22 @@ public function savesStatus() $storage->setStatus($service, Ganesha::STATUS_TRIPPED); $this->assertSame($storage->getStatus($service), Ganesha::STATUS_TRIPPED); } + + /** + * @test + */ + public function getLastFailureTimeWithRollingTimeWindow() + { + $r = new \Redis(); + $r->connect( + getenv('GANESHA_EXAMPLE_REDIS') ? getenv('GANESHA_EXAMPLE_REDIS') : 'localhost' + ); + $r->flushAll(); + $storage = new Storage(new Redis(($r)), null); + + $service = 'test'; + $storage->incrementFailureCount($service); + + $this->assertNotNull($storage->getLastFailureTime($service)); + } } From ab18588bda73d051dee70a366b00efd1391c6e13 Mon Sep 17 00:00:00 2001 From: "akihito.nakano" Date: Sun, 23 Dec 2018 14:49:18 +0900 Subject: [PATCH 2/2] Fix lastFailureKey() --- src/Ganesha/Storage.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Ganesha/Storage.php b/src/Ganesha/Storage.php index 27b3a44..d7b9ebd 100644 --- a/src/Ganesha/Storage.php +++ b/src/Ganesha/Storage.php @@ -333,7 +333,12 @@ private function rejectionKey($service) */ private function lastFailureKey($service) { - return $this->prefix($service) . self::KEY_SUFFIX_LAST_FAILURE_TIME; + return $this->supportRollingTimeWindow() + // If the adapter supports RollingTimeWindow use failureKey() instead, + // because Redis doesn't save lastFailureTime. + // @see Ackintosh\Ganesha\Storage\Adapter\Redis#saveLastFailureTime() + ? $this->failureKey($service) + : $this->prefix($service) . self::KEY_SUFFIX_LAST_FAILURE_TIME; } /**