Skip to content

Commit

Permalink
Add support for phpredis 6 (#22)
Browse files Browse the repository at this point in the history
* Update ext-redis requirement

* Remove unnessary lines

* Fix tests

* Update CI

* Fix code style

* Use docker redis

* Add will returng

---------

Co-authored-by: Alexander Schranz <alexander@sulu.io>
  • Loading branch information
martinlagler and alexander-schranz committed Jan 17, 2024
1 parent a892dd4 commit 74f3ab4
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 25 deletions.
27 changes: 17 additions & 10 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,28 @@ jobs:
env:
SYMFONY_DEPRECATIONS_HELPER: disabled

services:
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
- php-version: '8.2'
dependency-versions: 'highest'
php-extensions: 'redis'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: disabled

- php-version: '8.3'
dependency-versions: 'highest'
php-extensions: 'redis'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: disabled

steps:
- name: Checkout project
uses: actions/checkout@v2

- name: Start Docker services
run: |
docker compose up --wait
- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'phpdoc_to_comment' => [
'ignored_tags' => ['todo', 'var'],
],
'nullable_type_declaration_for_default_null_value' => true,
])
->setFinder($finder);

Expand Down
2 changes: 1 addition & 1 deletion Command/TrimRedisStreamCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

/** @var int $x */
$x = $redis->xtrim($stream, (int) $maxLength, true);
$x = $redis->xtrim($stream, (string) $maxLength, true);
if ($errorMessage = $redis->getLastError()) {
throw new \RuntimeException($errorMessage);
}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ And you can consume the messages with:
bin/console messenger:consume-messages redis_stream
```

Have also a look at the the [messenger component documentation](https://symfony.com/doc/current/components/messenger.html) and [messenger usage documentation](https://symfony.com/doc/current/messenger.html).
Have also a look at the [messenger component documentation](https://symfony.com/doc/current/components/messenger.html) and [messenger usage documentation](https://symfony.com/doc/current/messenger.html).


## Commands

Messages in streams wont be removed by default. Therefor this bundle provides a command:
Messages in streams won't be removed by default. Therefor this bundle provides a command:

```
bin/console redis-transport:trim <redis-dsn> --maxlen 1000
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Transport/RedisStreamSenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public function testSend(): void
if (\class_exists(RedisReceiver::class) && \class_exists(Connection::class)) {
$redisReceiver = new RedisReceiver(
Connection::fromDsn(\sprintf(
'redis-stream://%s:%s/my_test_stream/my_group',
'redis-stream://%s:%s/my_test_stream/my_group?serializer=0',
\getenv('REDIS_HOST'),
\getenv('REDIS_PORT')
), [], $this->redis)
);
} else {
$redisReceiver = new \Symfony\Component\Messenger\Transport\RedisExt\RedisReceiver(
\Symfony\Component\Messenger\Transport\RedisExt\Connection::fromDsn(\sprintf(
'redis-stream://%s:%s/my_test_stream/my_group',
'redis-stream://%s:%s/my_test_stream/my_group?serializer=0',
\getenv('REDIS_HOST'),
\getenv('REDIS_PORT')
), [], $this->redis)
Expand Down
4 changes: 3 additions & 1 deletion Tests/Unit/Command/TrimRedisStreamCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public function testExecute(): void
$redis->connect('127.0.0.1', '6739')->shouldBeCalled();
$redis->getLastError()->willReturn(null)->shouldBeCalled();
$redis->auth('password')->shouldBeCalled();
$redis->xtrim('stream', 1000, true)->shouldBeCalled();
$redis->xtrim('stream', '1000', true)
->willReturn(1)
->shouldBeCalled();

$command = new TrimRedisStreamCommand($redis->reveal());
$command->run($input, $output);
Expand Down
7 changes: 0 additions & 7 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,3 @@
if (!\file_exists($file)) {
throw new RuntimeException('Install dependencies to run test suite.');
}

if (!\file_exists(__DIR__ . '/var/cache')) {
// To speed up multiple tests do this only when cache folder not exists
if (\system(\sprintf('php %s ongr:es:index:create --manager location --if-not-exists', __DIR__ . '/bin/console'))) {
throw new RuntimeException('Could not find elasticsearch instance!');
}
}
2 changes: 1 addition & 1 deletion Tests/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ framework:
'HandcraftedInTheAlps\Bundle\RedisTransportBundle\Message\DomainEventMessage':
senders: ['redis_stream']
transports:
redis_stream: 'redis-stream://%env(resolve:REDIS_HOST)%:%env(resolve:REDIS_PORT)%/my_test_stream/my_group/my_consumer'
redis_stream: 'redis-stream://%env(resolve:REDIS_HOST)%:%env(resolve:REDIS_PORT)%/my_test_stream/my_group/my_consumer?serializer=0'
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"require": {
"php": "^7.3 || ^8.0",
"ext-redis": "^4.2 || ^5.0",
"ext-redis": "^4.2 || ^5.0 || ^6.0",
"symfony/messenger": "^4.3 || ^5.4 || ^6.0",
"symfony/config": "^3.4 || ^4.0 || ^5.4 || ^6.0",
"symfony/dependency-injection": "^3.4 || ^4.0 || ^5.4 || ^6.0",
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
redis:
image: redis/redis-stack:7.2.0-v6
ports:
- 6379:6379 # redis server
- 8001:8001 # redis insight
# environment:
# REDIS_ARGS: --requirepass supersecure
volumes:
- redisearch-data:/data

volumes:
redisearch-data:

0 comments on commit 74f3ab4

Please sign in to comment.