diff --git a/CHANGELOG.md b/CHANGELOG.md index 552b282a2..3603b9768 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,16 @@ * Command argument aliases are now shown in a separate column. +-------------------------------------------------------- + +### 10.0.12, 11.0.1 (2025-01-16) + +#### Compatibility + +* Replaced the deprecated SETEX and SETNX redis command calls with SET with the EX and NX options. + +-------------------------------------------------------- + ### 11.0.0 (2025-01-03) The major version bump is due to upping the required PHP version from `8.1` to `8.4` and a several breaking changes. Most applications built using Mako `10` should run on Mako `11` with just a few simple adjustments. diff --git a/src/mako/cache/stores/Redis.php b/src/mako/cache/stores/Redis.php index 14bd82918..b66ca3dfd 100644 --- a/src/mako/cache/stores/Redis.php +++ b/src/mako/cache/stores/Redis.php @@ -41,7 +41,7 @@ public function put(string $key, mixed $data, int $ttl = 0): bool return (bool) $this->redis->set($key, $data); } - return (bool) $this->redis->setex($key, $ttl, $data); + return (bool) $this->redis->set($key, $data, 'EX', $ttl); } /** @@ -54,7 +54,7 @@ public function putIfNotExists(string $key, mixed $data, int $ttl = 0): bool $data = is_numeric($data) ? $data : serialize($data); if ($ttl === 0) { - return (bool) $this->redis->setnx($key, $data); + return (bool) $this->redis->set($key, $data, 'NX'); } $lua = "return redis.call('exists', KEYS[1]) == 0 and redis.call('setex', KEYS[1], ARGV[1], ARGV[2])"; diff --git a/src/mako/session/stores/Redis.php b/src/mako/session/stores/Redis.php index eb73b8082..f46165ff9 100644 --- a/src/mako/session/stores/Redis.php +++ b/src/mako/session/stores/Redis.php @@ -33,7 +33,7 @@ public function __construct( */ public function write(#[SensitiveParameter] string $sessionId, array $sessionData, int $dataTTL): void { - $this->redis->setex("{$this->prefix}{$sessionId}", $dataTTL, serialize($sessionData)); + $this->redis->set("{$this->prefix}{$sessionId}", serialize($sessionData), 'EX', $dataTTL); } /** diff --git a/tests/unit/cache/stores/RedisTest.php b/tests/unit/cache/stores/RedisTest.php index cb131a763..04176f2e7 100644 --- a/tests/unit/cache/stores/RedisTest.php +++ b/tests/unit/cache/stores/RedisTest.php @@ -94,7 +94,7 @@ public function testPut(): void $client = $this->getRedisClient(); - $client->shouldReceive('setex')->once()->with('foo', 3600, 123)->andReturn(true); + $client->shouldReceive('set')->once()->with('foo', 123, 'EX', 3600)->andReturn(true); $redis = new Redis($client); @@ -104,7 +104,7 @@ public function testPut(): void $client = $this->getRedisClient(); - $client->shouldReceive('setex')->once()->with('foo', 3600, serialize('foo'))->andReturn(true); + $client->shouldReceive('set')->once()->with('foo', serialize('foo'), 'EX', 3600)->andReturn(true); $redis = new Redis($client); @@ -118,7 +118,7 @@ public function testPutIfNotExists(): void { $client = $this->getRedisClient(); - $client->shouldReceive('setNx')->once()->with('foo', 123)->andReturn(true); + $client->shouldReceive('set')->once()->with('foo', 123, 'NX')->andReturn(true); $redis = new Redis($client); @@ -128,7 +128,7 @@ public function testPutIfNotExists(): void $client = $this->getRedisClient(); - $client->shouldReceive('setNx')->once()->with('foo', serialize('foo'))->andReturn(true); + $client->shouldReceive('set')->once()->with('foo', serialize('foo'), 'NX')->andReturn(true); $redis = new Redis($client); diff --git a/tests/unit/session/stores/RedisTest.php b/tests/unit/session/stores/RedisTest.php index 2ed64bf2b..ecff3ffe8 100644 --- a/tests/unit/session/stores/RedisTest.php +++ b/tests/unit/session/stores/RedisTest.php @@ -31,7 +31,7 @@ public function testWrite(): void { $client = $this->getRedisClient(); - $client->shouldReceive('setex')->once()->with('sess_123', 123, serialize(['data'])); + $client->shouldReceive('set')->once()->with('sess_123', serialize(['data']), 'EX', 123); $redis = new Redis($client);