Skip to content

Commit

Permalink
Merge pull request #31020 from matt-allan/redis-connection-macroable
Browse files Browse the repository at this point in the history
[6.x] Make the Redis Connection macroable
  • Loading branch information
taylorotwell committed Jan 5, 2020
2 parents eff4ac8 + 27ddc2e commit c788434
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Illuminate/Redis/Connections/Connection.php
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
}
14 changes: 14 additions & 0 deletions tests/Redis/RedisConnectionTest.php
Expand Up @@ -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 = [
Expand Down

0 comments on commit c788434

Please sign in to comment.