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; } /** 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)); + } }