diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e9f6d2e4..41b16fce 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -42,7 +42,7 @@ jobs: run: | # Mapping of original redis versions to client test containers declare -A redis_clients_version_mapping=( - ["8.8"]="8.8-m02" + ["8.8"]="unstable-24805570909-debian" ["8.6"]="8.6.1" ["8.4"]="8.4.0" ["8.2"]="8.2.2" diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fa1b54a..767a01e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Added new COUNT aggregator for Sorted Set commands (#1668) - Added XNACK support (#1666) - Added support for multiple aggregators for TS range commands (#1670) +- Added testing for subkey notification channels (#1671) ### Changed - Include command name in unsupported container command error messages (#1653) diff --git a/tests/Predis/Consumer/PubSub/ConsumerTest.php b/tests/Predis/Consumer/PubSub/ConsumerTest.php index c6553caf..475e15d3 100644 --- a/tests/Predis/Consumer/PubSub/ConsumerTest.php +++ b/tests/Predis/Consumer/PubSub/ConsumerTest.php @@ -484,6 +484,55 @@ class ConsumerTest extends PredisTestCase $this->assertEquals('ECHO', $consumer->echo('ECHO')); } + /** + * @group connected + * @group relay-incompatible + * @requiresRedisVersion >= 8.7.2 + */ + public function testPubSubSupportsSubkeyNotificationSubscription(): void + { + $messages = []; + + $consumer = $this->createClient(['read_write_timeout' => 2]); + $consumer->connect(); + + $producer = $this->createClient(['read_write_timeout' => 2]); + $producer->connect(); + + // Save original notify-keyspace-events configuration + $previousConfig = $producer->config('GET', 'notify-keyspace-events'); + $previousValue = $previousConfig['notify-keyspace-events'] ?? ''; + + try { + // Enable keyspace notification + subkey notifications + $producer->config('SET', 'notify-keyspace-events', 'KEASTIV'); + + $pubsub = new PubSubConsumer($consumer); + $pubsub->subscribe( + '__subkeyspace@0__:test:hash', + '__subkeyevent@0__:hset', + "__subkeyspaceitem@0__:test:hash\nfield", + '__subkeyspaceevent@0__:hset|test:hash' + ); + + $producer->hset('test:hash', 'field', 'value'); + + foreach ($pubsub as $message) { + if ($message->kind !== 'message') { + continue; + } + + $messages[] = $message->payload; + $pubsub->stop(); + } + + $this->assertSameValues(['hset|5:field', '9:test:hash|5:field', 'hset', '5:field'], $messages); + } finally { + // Restore original notify-keyspace-events configuration + $producer->config('SET', 'notify-keyspace-events', $previousValue); + } + } + /** * @group connected * @requiresRedisVersion >= 2.0.0