Skip to content

Commit

Permalink
Merge pull request #80 from igoreus/redis-module
Browse files Browse the repository at this point in the history
Add credis module class
  • Loading branch information
colinmollenhour authored May 17, 2017
2 parents 958e188 + bce9102 commit 5bf1da9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ public function pUnsubscribe()
/**
* @param int $Iterator
* @param string $pattern
* @param int $Iterator
* @param int $count
* @return bool | Array
*/
public function scan(&$Iterator, $pattern = null, $count = null)
Expand Down
68 changes: 68 additions & 0 deletions Module.php
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);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"classmap": [
"Client.php",
"Cluster.php",
"Sentinel.php"
"Sentinel.php",
"Module.php"
]
}
}

0 comments on commit 5bf1da9

Please sign in to comment.