当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::eval方法代码示例

本文整理汇总了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());
    }
开发者ID:narrowspark,项目名称:framework,代码行数:20,代码来源:RedisQueue.php

示例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));
        }
    }
开发者ID:slaszu,项目名称:redismq,代码行数:51,代码来源:Queue.php

示例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;
    }
开发者ID:EdenPP,项目名称:SncRedisBundle,代码行数:21,代码来源:RedisSessionHandler.php

示例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);
 }
开发者ID:kohver,项目名称:redlock-php,代码行数:17,代码来源:RedLock.php


注:本文中的Predis\Client::eval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。