From 12711d133afd156e05080e5e1bedd3a281de99c4 Mon Sep 17 00:00:00 2001 From: Matt Wells Date: Mon, 13 Jul 2015 19:40:51 +0100 Subject: [PATCH] Switch back to using rpush Switches back to rpush to keep list order consistent with non capped collections --- src/Monolog/Handler/RedisHandler.php | 8 ++++---- tests/Monolog/Handler/RedisHandlerTest.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Monolog/Handler/RedisHandler.php b/src/Monolog/Handler/RedisHandler.php index 22ba4994..dd0e747e 100644 --- a/src/Monolog/Handler/RedisHandler.php +++ b/src/Monolog/Handler/RedisHandler.php @@ -75,15 +75,15 @@ class RedisHandler extends AbstractProcessingHandler { if($this->redisClient instanceof \Redis) { $this->redisClient->multi() - ->lpush($this->redisKey, $record["formatted"]) - ->ltrim($this->redisKey, 0, $this->capSize) + ->rpush($this->redisKey, $record["formatted"]) + ->ltrim($this->redisKey, -$this->capSize, -1) ->execute(); } else { $redisKey = $this->redisKey; $capSize = $this->capSize; $this->redisClient->transaction(function($tx) use($record, $redisKey, $capSize) { - $tx->lpush($redisKey, $record["formatted"]); - $tx->ltrim($redisKey, 0, $capSize); + $tx->rpush($redisKey, $record["formatted"]); + $tx->ltrim($redisKey, -$capSize, -1); }); } } diff --git a/tests/Monolog/Handler/RedisHandlerTest.php b/tests/Monolog/Handler/RedisHandlerTest.php index 088cef82..c415c722 100644 --- a/tests/Monolog/Handler/RedisHandlerTest.php +++ b/tests/Monolog/Handler/RedisHandlerTest.php @@ -71,7 +71,7 @@ class RedisHandlerTest extends TestCase public function testRedisHandleCapped() { - $redis = $this->getMock('Redis', array('multi', 'lpush', 'ltrim', 'execute')); + $redis = $this->getMock('Redis', array('multi', 'rpush', 'ltrim', 'execute')); // Redis uses multi $redis->expects($this->once()) @@ -79,7 +79,7 @@ class RedisHandlerTest extends TestCase ->will($this->returnSelf()); $redis->expects($this->once()) - ->method('lpush') + ->method('rpush') ->will($this->returnSelf()); $redis->expects($this->once()) @@ -101,10 +101,10 @@ class RedisHandlerTest extends TestCase { $redis = $this->getMock('Predis\Client', array('transaction')); - $redisTransaction = $this->getMock('Predis\Client', array('lpush', 'ltrim')); + $redisTransaction = $this->getMock('Predis\Client', array('rpush', 'ltrim')); $redisTransaction->expects($this->once()) - ->method('lpush') + ->method('rpush') ->will($this->returnSelf()); $redisTransaction->expects($this->once())