36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Benzine\Redis;
|
|
|
|
class Redis extends \Redis
|
|
{
|
|
/** @var Lua\LuaExtension[] */
|
|
private array $scripts;
|
|
|
|
public function __call($name, $arguments)
|
|
{
|
|
foreach ($this->scripts as $script) {
|
|
foreach ($script->getFunctionNames() as $functionName) {
|
|
if (strtolower($name) == strtolower($functionName)) {
|
|
$script->load();
|
|
|
|
return $this->evalSha($script->getHash(), $arguments);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function initialiseExtensions(): void
|
|
{
|
|
$this->scripts[] = new Lua\SetIfHigher($this);
|
|
$this->scripts[] = new Lua\SetIfLower($this);
|
|
$this->scripts[] = new Lua\ZAddIfHigher($this);
|
|
$this->scripts[] = new Lua\ZAddIfLower($this);
|
|
}
|
|
|
|
public function connect($host, $port = 6379, $timeout = 0.0, $reserved = null, $retryInterval = 0, $readTimeout = 0.0): void
|
|
{
|
|
parent::connect($host, $port, $timeout, $reserved, $retryInterval, $readTimeout);
|
|
$this->initialiseExtensions();
|
|
}
|
|
}
|