Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedisMock set method expire time value is in seconds #96

Open
kronostof opened this issue Oct 25, 2021 · 0 comments
Open

RedisMock set method expire time value is in seconds #96

kronostof opened this issue Oct 25, 2021 · 0 comments

Comments

@kronostof
Copy link

kronostof commented Oct 25, 2021

The set method signature on RedisMock seems to be wrong and store ttl in second.

However set should support milliseconds for ttl definition.

Proposal
public function set($key, $value, $options = null, $ttl = null)
{
    /**
     * Per https://redis.io/commands/set#options
     * EX seconds -- Set the specified expire time, in seconds.
     * PX milliseconds -- Set the specified expire time, in milliseconds.
     * NX -- Only set the key if it does not already exist.
     * XX -- Only set the key if it already exist.
     */
    if (!is_null($options) && !in_array($options, ['ex', 'px', 'nx', 'xx'])) {
        $this->returnPipedInfo('(error) ERR syntax error');
    }
    if ('nx'=== $options && $this->get($key)) {
        return $this->returnPipedInfo(0);
    }
    if ('xx' === $options && !$this->get($key)) {
        return $this->returnPipedInfo(0);
    }

    if ($options === 'ex') {
        $ttl = $ttl;
    } elseif ($options === 'px') {
        $ttl = $ttl / 1000;
    }

    self::$dataValues[$this->storage][$key] = $value;
    self::$dataTypes[$this->storage][$key] = 'string';

    if (!is_null($ttl)) {
        self::$dataTtl[$this->storage][$key] = microtime(true) + $ttl;
    }

As it will be impacted, We should update RedisSessionHandler, and check that ttl resolution is compatible with symfony session resolution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant