Skip to content

Commit 6e4f42e

Browse files
committed
Fix redis stream editing with same id
1 parent abfcfa2 commit 6e4f42e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Dashboards/Redis/RedisTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ private function form(): string {
382382
}
383383

384384
if (isset($_GET['key']) && $_GET['form'] === 'edit' && $this->redis->exists($key)) {
385-
[$value, $index, $score, $hash_key] = $this->getKeyValue($type, $key);
385+
[$value, $index, $score, $hash_key, $stream_id] = $this->getKeyValue($type, $key);
386386
}
387387

388388
$value = Value::converter($value, $encoder, 'view');

src/Dashboards/Redis/RedisTypes.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private function getKeyValue(string $type, string $key): array {
7272
$index = null;
7373
$score = 0;
7474
$hash_key = '';
75+
$stream_id = '*';
7576

7677
switch ($type) {
7778
case 'string':
@@ -99,7 +100,8 @@ private function getKeyValue(string $type, string $key): array {
99100
break;
100101
case 'stream':
101102
$ranges = $this->redis->xRange($key, '-', '+');
102-
$value = $ranges[Http::get('stream_id', '')] ?? [];
103+
$stream_id = Http::get('stream_id', '');
104+
$value = $ranges[$stream_id] ?? [];
103105
$value = json_encode($value, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
104106
break;
105107
case 'rejson':
@@ -109,7 +111,7 @@ private function getKeyValue(string $type, string $key): array {
109111
$value = '';
110112
}
111113

112-
return [$value, $index, $score, $hash_key];
114+
return [$value, $index, $score, $hash_key, $stream_id];
113115
}
114116

115117
/**
@@ -183,6 +185,11 @@ public function store(string $type, string $key, string $value, string $old_valu
183185
$this->redis->hSet($key, $options['hash_key'], $value);
184186
break;
185187
case 'stream':
188+
if ($options['stream_id'] === Http::get('stream_id', '')) {
189+
[$timestamp, $sequence] = array_pad(explode('-', Http::get('stream_id', '')), 2, 0);
190+
$options['stream_id'] = $timestamp.'-'.((int) $sequence + 1);
191+
}
192+
186193
if (Http::get('stream_id', '') !== '') {
187194
$this->redis->xDel($key, [Http::get('stream_id', '')]);
188195
}

0 commit comments

Comments
 (0)