|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Predis package. |
| 5 | + * |
| 6 | + * (c) 2009-2020 Daniele Alessandri |
| 7 | + * (c) 2021-2025 Till Krüss |
| 8 | + * |
| 9 | + * For the full copyright and license information, please view the LICENSE |
| 10 | + * file that was distributed with this source code. |
| 11 | + */ |
| 12 | + |
| 13 | +namespace Predis\Command\Redis; |
| 14 | + |
| 15 | +use Predis\Command\PrefixableCommand as RedisCommand; |
| 16 | + |
| 17 | +/** |
| 18 | + * This is a transitional command. In the next major version this command will replace XREADGROUP. |
| 19 | + */ |
| 20 | +class XREADGROUP_CLAIM extends RedisCommand |
| 21 | +{ |
| 22 | + public function getId() |
| 23 | + { |
| 24 | + return 'XREADGROUP'; |
| 25 | + } |
| 26 | + |
| 27 | + public function setArguments(array $arguments) |
| 28 | + { |
| 29 | + $processedArguments = ['GROUP', $arguments[0], $arguments[1]]; |
| 30 | + |
| 31 | + if (count($arguments) >= 4 && null !== $arguments[3]) { |
| 32 | + array_push($processedArguments, 'COUNT', $arguments[3]); |
| 33 | + } |
| 34 | + |
| 35 | + if (count($arguments) >= 5 && null !== $arguments[4]) { |
| 36 | + array_push($processedArguments, 'BLOCK', $arguments[4]); |
| 37 | + } |
| 38 | + |
| 39 | + if (count($arguments) >= 6 && false !== $arguments[5]) { |
| 40 | + $processedArguments[] = 'NOACK'; |
| 41 | + } |
| 42 | + |
| 43 | + if (count($arguments) >= 7 && false !== $arguments[6]) { |
| 44 | + array_push($processedArguments, 'CLAIM', $arguments[6]); |
| 45 | + } |
| 46 | + |
| 47 | + array_push($processedArguments, 'STREAMS', ...array_keys($arguments[2]), ...array_values($arguments[2])); |
| 48 | + |
| 49 | + parent::setArguments($processedArguments); |
| 50 | + } |
| 51 | + |
| 52 | + public function parseResponse($data) |
| 53 | + { |
| 54 | + if (!is_array($data) || $data === array_values($data)) { |
| 55 | + return $data; |
| 56 | + } |
| 57 | + |
| 58 | + // Relay |
| 59 | + $result = []; |
| 60 | + foreach ($data as $key => $value) { |
| 61 | + $group = [$key, $value]; |
| 62 | + $result[] = $group; |
| 63 | + } |
| 64 | + |
| 65 | + return $result; |
| 66 | + } |
| 67 | + |
| 68 | + public function prefixKeys($prefix) |
| 69 | + { |
| 70 | + $arguments = $this->getArguments(); |
| 71 | + $keyIdsStartingIndex = array_search('STREAMS', $arguments) + 1; |
| 72 | + $keysAndIdsCount = count($arguments) - $keyIdsStartingIndex; |
| 73 | + $keysCount = $keysAndIdsCount / 2; |
| 74 | + |
| 75 | + for ($i = $keyIdsStartingIndex; $i < $keyIdsStartingIndex + $keysCount; $i++) { |
| 76 | + $arguments[$i] = $prefix . $arguments[$i]; |
| 77 | + } |
| 78 | + |
| 79 | + parent::setRawArguments($arguments); |
| 80 | + } |
| 81 | +} |
0 commit comments