本文整理汇总了PHP中Predis\Client::eval方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::eval方法的具体用法?PHP Client::eval怎么用?PHP Client::eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::eval方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: migrateExpiredJobs
/**
* Migrate the delayed jobs that are ready to the regular queue.
*
* @param string $from
* @param string $to
*/
public function migrateExpiredJobs(string $from, string $to)
{
$script = <<<'LUA'
local val = redis.call('zrangebyscore', KEYS[1], '-inf', KEYS[3])
if(next(val) ~= nil) then
redis.call('zremrangebyrank', KEYS[1], 0, #val - 1)
for i = 1, #val, 100 do
redis.call('rpush', KEYS[2], unpack(val, i, math.min(i+99, #val)))
end
end
return true
LUA;
$this->redis->eval($script, 3, $from, $to, $this->getTime());
}
示例2: getTaskList
/**
* Copy data from queue to new process list with given size
*
* @param int $size
* @return TaskList
*/
public function getTaskList($size = 100)
{
/**
* copy part of queue to other redis list
*/
$taskListUniqueName = $this->getName() . ':' . md5(microtime() . mt_rand());
$queueName = $this->getName();
$queueNameTaskLists = $this->getQueueTaskListsName();
$timestamp = time();
$script = '
local taskListUniqueName = KEYS[1]
local queueName = KEYS[2]
local size = KEYS[3]
local timestamp = KEYS[4]
local queueNameTaskList = KEYS[5]
-- check if key is unique
local is_unique = redis.call("exists", taskListUniqueName)
if is_unique == 1 then return 0 end
for i=1,size do
redis.call("RPOPLPUSH",queueName,taskListUniqueName)
end
redis.call("hset",queueNameTaskList,taskListUniqueName,timestamp)
return 1
';
/**
* 1. check llen of queue
*/
if ($this->getLength() == 0) {
throw new Exception("Queue '{$queueName}' is empty or not exists !");
}
/**
* 2. create task list
*/
$res = $this->client->eval($script, 5, $taskListUniqueName, $queueName, $size, $timestamp, $queueNameTaskLists);
if ($res == 0) {
throw new Exception("Task list '{$taskListUniqueName}' exists, it is very rare problem, try run process again !");
} elseif ($res == 1) {
return new TaskList($taskListUniqueName, $this);
} else {
throw new Exception("Strange problem occured ! res = " . var_export($res, true));
}
}
示例3: unlockSession
/**
* Unlock the session data.
*/
private function unlockSession()
{
// If we have the right token, then delete the lock
$script = <<<LUA
if redis.call("GET", KEYS[1]) == ARGV[1] then
return redis.call("DEL", KEYS[1])
else
return 0
end
LUA;
if ($this->redis instanceof \Redis) {
$this->redis->eval($script, array($this->prefix . $this->lockKey, $this->token), 1);
} else {
$this->redis->eval($script, 1, $this->prefix . $this->lockKey, $this->token);
}
$this->locked = false;
$this->token = null;
}
示例4: unlockInstance
/**
* @param Predis $Instance
* @param string $resource
* @param string $token
* @return mixed
*/
private function unlockInstance(Predis $Instance, $resource, $token)
{
$script = '
if redis.call("GET", KEYS[1]) == ARGV[1] then
return redis.call("DEL", KEYS[1])
else
return 0
end
';
return $Instance->eval($script, 1, $resource, $token);
}