Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Redis Adapter checks majorversion with version_compare but RedisResourceManager returns integer #107

Closed
boesing opened this issue Jun 28, 2016 · 0 comments
Assignees
Labels

Comments

@boesing
Copy link
Member

boesing commented Jun 28, 2016

The RedisResourceManager always returns integer as version information. Therefore, the check in Redis Adapter wont work as expected.

    /**
     * Get redis server version
     *
     * @param string $id
     * @return int
     * @throws Exception\RuntimeException
     */
    public function getMajorVersion($id)
    {
        // check resource id and initialize the resource
        $this->getResource($id);

        return (int) $this->resources[$id]['version'];
    }
            $redisVersion = $this->resourceManager->getMajorVersion($this->resourceId);

            // redis >= 2.8
            // The command 'pttl' returns -2 if the item does not exist
            // and -1 if the item has no associated expire
            if (version_compare($redisVersion, '2.8',  '>=')) {
                $pttl = $redis->pttl($this->namespacePrefix . $normalizedKey);
                if ($pttl <= -2) {
                    return false;
                }
                $metadata['ttl'] = ($pttl == -1) ? null : $pttl / 1000;

            // redis >= 2.6
            // The command 'pttl' returns -1 if the item does not exist or the item as no associated expire
            } elseif (version_compare($redisVersion, '2.6', '>=')) {
                $pttl = $redis->pttl($this->namespacePrefix . $normalizedKey);
                if ($pttl <= -1) {
                    if (!$this->internalHasItem($normalizedKey)) {
                        return false;
                    }
                    $metadata['ttl'] = null;
                } else {
                    $metadata['ttl'] = $pttl / 1000;
                }

            // redis >= 2
            // The command 'pttl' is not supported but 'ttl'
            // The command 'ttl' returns 0 if the item does not exist same as if the item is going to be expired
            // NOTE: In case of ttl=0 we return false because the item is going to be expired in a very near future
            //       and then doesn't exist any more
            } elseif (version_compare($redisVersion, '2', '>=')) {
                $ttl = $redis->ttl($this->namespacePrefix . $normalizedKey);
                if ($ttl <= -1) {
                    if (!$this->internalHasItem($normalizedKey)) {
                        return false;
                    }
                    $metadata['ttl'] = null;
                } else {
                    $metadata['ttl'] = $ttl;
                }

            // redis < 2
            // The commands 'pttl' and 'ttl' are not supported
            // but item existence have to be checked
            } elseif (!$this->internalHasItem($normalizedKey)) {
                return false;
            }
@marc-mabe marc-mabe self-assigned this Aug 16, 2016
@marc-mabe marc-mabe added the bug label Aug 16, 2016
marc-mabe added a commit that referenced this issue Sep 19, 2016
fixed #107: fixed redis server version test in Redis::internalGetMetadata()
marc-mabe added a commit that referenced this issue Sep 19, 2016
marc-mabe added a commit that referenced this issue Sep 19, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants