forked from jdp/redisent
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from igoreus/redis-module
Add credis module class
- Loading branch information
Showing
3 changed files
with
71 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/** | ||
* Credis_Module | ||
* | ||
* Implements Redis Modules support. see http://redismodules.com | ||
* | ||
* @author Igor Veremchuk <igor.veremchuk@gmail.com> | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @package Credis_Module | ||
*/ | ||
class Credis_Module | ||
{ | ||
const MODULE_COUNTING_BLOOM_FILTER = 'CBF'; | ||
|
||
/** @var Credis_Client */ | ||
protected $client; | ||
|
||
/** @var string */ | ||
protected $moduleName; | ||
|
||
/** | ||
* @param Credis_Client $client | ||
* @param string $module | ||
*/ | ||
public function __construct(Credis_Client $client, $module = null) | ||
{ | ||
$client->forceStandalone(); // Redis Modules command not currently supported by phpredis | ||
$this->client = $client; | ||
|
||
if (isset($module)) { | ||
$this->setModule($module); | ||
} | ||
} | ||
|
||
/** | ||
* Clean up client on destruct | ||
*/ | ||
public function __destruct() | ||
{ | ||
$this->client->close(); | ||
} | ||
|
||
/** | ||
* @param $moduleName | ||
* @return $this | ||
*/ | ||
public function setModule($moduleName) | ||
{ | ||
$this->moduleName = (string) $moduleName; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param string $args | ||
* @return mixed | ||
*/ | ||
public function __call($name, $args) | ||
{ | ||
if ($this->moduleName === null) { | ||
throw new \LogicException('Module must be set.'); | ||
} | ||
|
||
return call_user_func(array($this->client, sprintf('%s.%s', $this->moduleName, $name)), $args); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -17,7 +17,8 @@ | |
"classmap": [ | ||
"Client.php", | ||
"Cluster.php", | ||
"Sentinel.php" | ||
"Sentinel.php", | ||
"Module.php" | ||
] | ||
} | ||
} |