Skip to content

RedisMock set method expire time value is in seconds #96

@kronostof

Description

@kronostof

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions