diff --git a/src/Illuminate/Redis/Connections/Connection.php b/src/Illuminate/Redis/Connections/Connection.php index 0babdfa5287a..95af91e7fffc 100644 --- a/src/Illuminate/Redis/Connections/Connection.php +++ b/src/Illuminate/Redis/Connections/Connection.php @@ -7,9 +7,14 @@ use Illuminate\Redis\Events\CommandExecuted; use Illuminate\Redis\Limiters\ConcurrencyLimiterBuilder; use Illuminate\Redis\Limiters\DurationLimiterBuilder; +use Illuminate\Support\Traits\Macroable; abstract class Connection { + use Macroable { + __call as macroCall; + } + /** * The Redis client. * @@ -208,6 +213,10 @@ public function unsetEventDispatcher() */ public function __call($method, $parameters) { + if (static::hasMacro($method)) { + return $this->macroCall($method, $parameters); + } + return $this->command($method, $parameters); } } diff --git a/tests/Redis/RedisConnectionTest.php b/tests/Redis/RedisConnectionTest.php index aaa4bf52ad5f..f34852439124 100644 --- a/tests/Redis/RedisConnectionTest.php +++ b/tests/Redis/RedisConnectionTest.php @@ -547,6 +547,20 @@ public function testItPersistsConnection() ); } + public function testMacroable() + { + Connection::macro('foo', function () { + return 'foo'; + }); + + foreach ($this->connections() as $redis) { + $this->assertSame( + 'foo', + $redis->foo() + ); + } + } + public function connections() { $connections = [