-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This rewrite the Redis layer to function more like database or cache drivers… a new Redis factory is introduced to retrieve Redis connection instances. Different Redis connection instances are introduced to account for differences between the two drivers (Predis and PhpRedis).
- Loading branch information
1 parent
0fd8b63
commit 1ef8b9c
Showing
26 changed files
with
526 additions
and
572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Illuminate\Contracts\Redis; | ||
|
||
interface Factory | ||
{ | ||
/** | ||
* Get a Redis connection by name. | ||
* | ||
* @param string $name | ||
* @return \Illuminate\Redis\Connections\Connection | ||
*/ | ||
public function connection($name = null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace Illuminate\Redis\Connections; | ||
|
||
use Closure; | ||
|
||
abstract class Connection | ||
{ | ||
/** | ||
* The Predis client. | ||
* | ||
* @var \Predis\Client | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* Subscribe to a set of given channels for messages. | ||
* | ||
* @param array|string $channels | ||
* @param \Closure $callback | ||
* @param string $method | ||
* @return void | ||
*/ | ||
abstract public function createSubscription($channels, Closure $callback, $method = 'subscribe'); | ||
|
||
/** | ||
* Get the underlying Redis client. | ||
* | ||
* @return mixed | ||
*/ | ||
public function client() | ||
{ | ||
return $this->client; | ||
} | ||
|
||
/** | ||
* Subscribe to a set of given channels for messages. | ||
* | ||
* @param array|string $channels | ||
* @param \Closure $callback | ||
* @param string $method | ||
* @return void | ||
*/ | ||
public function subscribe($channels, Closure $callback) | ||
{ | ||
return $this->createSubscription($channels, $callback, __FUNCTION__); | ||
} | ||
|
||
/** | ||
* Subscribe to a set of given channels with wildcards. | ||
* | ||
* @param array|string $channels | ||
* @param \Closure $callback | ||
* @return void | ||
*/ | ||
public function psubscribe($channels, Closure $callback) | ||
{ | ||
return $this->createSubscription($channels, $callback, __FUNCTION__); | ||
} | ||
|
||
/** | ||
* Run a command against the Redis database. | ||
* | ||
* @param string $method | ||
* @param array $parameters | ||
* @return mixed | ||
*/ | ||
public function command($method, array $parameters = []) | ||
{ | ||
return $this->client->{$method}(...$parameters); | ||
} | ||
|
||
/** | ||
* Pass other method calls down to the underlying client. | ||
* | ||
* @param string $method | ||
* @param array $parameters | ||
* @return mixed | ||
*/ | ||
public function __call($method, $parameters) | ||
{ | ||
return $this->command($method, $parameters); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Illuminate\Redis\Connections; | ||
|
||
class PhpRedisClusterConnection extends PhpRedisConnection | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Illuminate\Redis\Connections; | ||
|
||
use Closure; | ||
|
||
class PhpRedisConnection extends Connection | ||
{ | ||
/** | ||
* Create a new Predis connection. | ||
* | ||
* @param \Predis\Client $client | ||
* @return void | ||
*/ | ||
public function __construct($client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* Evaluate a Lua script and return the result. | ||
* | ||
* @param string $script | ||
* @param int $numberOfKeys | ||
* @param dynamic $arguments | ||
* @return mixed | ||
*/ | ||
public function eval($script, $numberOfKeys, ...$arguments) | ||
{ | ||
return $this->client->eval($script, $arguments, $numberOfKeys); | ||
} | ||
|
||
/** | ||
* Subscribe to a set of given channels for messages. | ||
* | ||
* @param array|string $channels | ||
* @param \Closure $callback | ||
* @return void | ||
*/ | ||
public function subscribe($channels, Closure $callback) | ||
{ | ||
$this->client->subscribe((array) $channels, function ($redis, $channel, $message) use ($callback) { | ||
$callback($message, $channel); | ||
}); | ||
} | ||
|
||
/** | ||
* Subscribe to a set of given channels with wildcards. | ||
* | ||
* @param array|string $channels | ||
* @param \Closure $callback | ||
* @return void | ||
*/ | ||
public function psubscribe($channels, Closure $callback) | ||
{ | ||
$this->client->psubscribe((array) $channels, function ($redis, $pattern, $channel, $message) use ($callback) { | ||
$callback($message, $channel); | ||
}); | ||
} | ||
|
||
/** | ||
* Subscribe to a set of given channels for messages. | ||
* | ||
* @param array|string $channels | ||
* @param \Closure $callback | ||
* @param string $method | ||
* @return void | ||
*/ | ||
public function createSubscription($channels, Closure $callback, $method = 'subscribe') | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Illuminate\Redis\Connections; | ||
|
||
class PredisClusterConnection extends PredisConnection | ||
{ | ||
// | ||
} |
Oops, something went wrong.