BedrockStreaming / RedisMock

A simple PHP Redis mock
http://tech.m6web.fr/redismock-qui-a-bouchonne-mon-redis.html
MIT License
81 stars 60 forks source link

RedisMock set method expire time value is in seconds #96

Open kronostof opened 3 years ago

kronostof commented 3 years ago

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