Skip to content

Commit 6bf7ed5

Browse files
authored
Merge pull request #52 from MacFJA/phpredis-raw-command-issue-46
Set option to Phpredis to return raw response
2 parents f5169c9 + 4a1692e commit 6bf7ed5

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323

2424
- Missing default values on highlight option ([Issue#38])
2525
- Don't throw an exception if the result of the index definition is incorrect ([Issue#46])
26+
- Phpredis extension don't return raw response ([Issue#46])
2627

2728
### Changed
2829

phpstan.neon

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ parameters:
33
paths:
44
- src
55
- tests
6+
stubFiles:
7+
- vendor/ukko/phpredis-phpdoc/src/Redis.php
68
excludePaths:
79
analyse:
810
- tests/psalm/stubs/phpiredis.php

src/Redis/Client/PhpredisClient.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private function __construct(Redis $redis)
4040
{
4141
if (!static::supports($redis)) {
4242
throw new RuntimeException($this->getMissingMessage('phpredis', true, [
43-
Redis::class => ['rawCommand', 'multi', 'exec'],
43+
Redis::class => ['rawCommand', 'multi', 'exec', 'getOption', 'setOption'],
4444
]));
4545
}
4646
$this->redis = $redis;
@@ -49,13 +49,19 @@ private function __construct(Redis $redis)
4949
public function execute(Command $command)
5050
{
5151
$arguments = $command->getArguments();
52+
53+
$originalValue = $this->redis->getOption(Redis::OPT_REPLY_LITERAL) ?? false;
54+
$this->redis->setOption(Redis::OPT_REPLY_LITERAL, true);
55+
5256
if (0 === count($arguments)) {
5357
/** @psalm-suppress TooFewArguments */
5458
$rawResponse = $this->redis->rawCommand($command->getId());
5559
} else {
5660
$rawResponse = $this->redis->rawCommand($command->getId(), ...$arguments);
5761
}
5862

63+
$this->redis->setOption(Redis::OPT_REPLY_LITERAL, $originalValue);
64+
5965
return $command->parseResponse($rawResponse);
6066
}
6167

@@ -64,6 +70,8 @@ public static function supports($redis): bool
6470
return $redis instanceof Redis
6571
&& method_exists($redis, 'rawCommand')
6672
&& method_exists($redis, 'multi')
73+
&& method_exists($redis, 'setOption')
74+
&& method_exists($redis, 'getOption')
6775
&& method_exists($redis, 'exec');
6876
}
6977

0 commit comments

Comments
 (0)