示例#1
0
    /**
     * @param RedisConnRef $conn
     * @param string $slot
     * @param float $now
     * @return int|bool False on failure
     */
    protected function registerAcquisitionTime(RedisConnRef $conn, $slot, $now)
    {
        static $script = <<<LUA
\t\tlocal kSlots,kSlotsNextRelease,kSlotWaits = unpack(KEYS)
\t\tlocal rSlot,rExpiry,rSess,rTime = unpack(ARGV)
\t\t-- If rSlot is 'w' then the client was told to wake up but got no slot
\t\tif rSlot ~= 'w' then
\t\t\t-- Update the slot "next release" time
\t\t\tredis.call('zAdd',kSlotsNextRelease,rTime + rExpiry,rSlot)
\t\t\t-- Always keep renewing the expiry on use
\t\t\tredis.call('expireAt',kSlots,math.ceil(rTime + rExpiry))
\t\t\tredis.call('expireAt',kSlotsNextRelease,math.ceil(rTime + rExpiry))
\t\tend
\t\t-- Unregister this process as waiting
\t\tredis.call('zRem',kSlotWaits,rSess)
\t\treturn 1
LUA;
        return $conn->luaEval($script, [$this->getSlotListKey(), $this->getSlotRTimeSetKey(), $this->getWaitSetKey(), $slot, $this->lockTTL, $this->session, $now], 3);
    }
示例#2
0
    /**
     * @param RedisConnRef $conn
     * @return array serialized string or false
     * @throws RedisException
     */
    protected function popAndAcquireBlob(RedisConnRef $conn)
    {
        static $script = <<<LUA
\t\t-- Pop an item off the queue
\t\tlocal id = redis.call('rPop',KEYS[1])
\t\tif not id then return false end
\t\t-- Allow new duplicates of this job
\t\tlocal sha1 = redis.call('hGet',KEYS[2],id)
\t\tif sha1 then redis.call('hDel',KEYS[3],sha1) end
\t\tredis.call('hDel',KEYS[2],id)
\t\t-- Mark the jobs as claimed and return it
\t\tredis.call('zAdd',KEYS[4],ARGV[1],id)
\t\tredis.call('hIncrBy',KEYS[5],id,1)
\t\treturn redis.call('hGet',KEYS[6],id)
LUA;
        return $conn->luaEval($script, array($this->getQueueKey('l-unclaimed'), $this->getQueueKey('h-sha1ById'), $this->getQueueKey('h-idBySha1'), $this->getQueueKey('z-claimed'), $this->getQueueKey('h-attempts'), $this->getQueueKey('h-data'), time()), 6);
    }
示例#3
0
    /**
     * @param RedisConnRef $conn
     * @return array Serialized string or false
     * @throws RedisException
     */
    protected function popAndAcquireBlob(RedisConnRef $conn)
    {
        static $script = <<<LUA
\t\tlocal kUnclaimed, kSha1ById, kIdBySha1, kClaimed, kAttempts, kData = unpack(KEYS)
\t\tlocal rTime = unpack(ARGV)
\t\t-- Pop an item off the queue
\t\tlocal id = redis.call('rPop',kUnclaimed)
\t\tif not id then
\t\t\treturn false
\t\tend
\t\t-- Allow new duplicates of this job
\t\tlocal sha1 = redis.call('hGet',kSha1ById,id)
\t\tif sha1 then redis.call('hDel',kIdBySha1,sha1) end
\t\tredis.call('hDel',kSha1ById,id)
\t\t-- Mark the jobs as claimed and return it
\t\tredis.call('zAdd',kClaimed,rTime,id)
\t\tredis.call('hIncrBy',kAttempts,id,1)
\t\treturn redis.call('hGet',kData,id)
LUA;
        return $conn->luaEval($script, array($this->getQueueKey('l-unclaimed'), $this->getQueueKey('h-sha1ById'), $this->getQueueKey('h-idBySha1'), $this->getQueueKey('z-claimed'), $this->getQueueKey('h-attempts'), $this->getQueueKey('h-data'), time()), 6);
    }
示例#4
0
	/**
	 * @param RedisConnRef $conn
	 * @return array serialized string or false
	 * @throws RedisException
	 */
	protected function popAndAcquireBlob( RedisConnRef $conn ) {
		static $script =
<<<LUA
		-- Pop an item off the queue
		local id = redis.call('rPop',KEYS[1])
		if not id then return false end
		-- Allow new duplicates of this job
		local sha1 = redis.call('hGet',KEYS[2],id)
		if sha1 then redis.call('hDel',KEYS[3],sha1) end
		redis.call('hDel',KEYS[2],id)
		-- Mark the jobs as claimed and return it
		redis.call('zAdd',KEYS[4],ARGV[1],id)
		redis.call('hIncrBy',KEYS[5],id,1)
		return redis.call('hGet',KEYS[6],id)
LUA;
		return $conn->luaEval( $script,
			array(
				$this->getQueueKey( 'l-unclaimed' ), # KEYS[1]
				$this->getQueueKey( 'h-sha1ById' ), # KEYS[2]
				$this->getQueueKey( 'h-idBySha1' ), # KEYS[3]
				$this->getQueueKey( 'z-claimed' ), # KEYS[4]
				$this->getQueueKey( 'h-attempts' ), # KEYS[5]
				$this->getQueueKey( 'h-data' ), # KEYS[6]
				time(), # ARGV[1] (injected to be replication-safe)
			),
			6 # number of first argument(s) that are keys
		);
	}