Skip to content

Commit 6f671d0

Browse files
committed
Update TypesTrait.php
1 parent 494a873 commit 6f671d0

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/Dashboards/Redis/TypesTrait.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ private function getKeyValue(Redis $redis, string $type, string $key): array {
134134
$hash_key = Http::get('hash_key', 'string', $keys[0]);
135135
$value = $redis->hGet($key, $hash_key);
136136
break;
137+
case 'stream':
138+
$ranges = $redis->xRange($key, '-', '+');
139+
$value = $ranges[Http::get('stream_id')];
140+
break;
137141
default:
138142
$value = '';
139143
}
@@ -207,9 +211,9 @@ private function saveKey(Redis $redis): void {
207211
$size = $redis->lLen($key);
208212
$index = $_POST['index'] ?? '';
209213

210-
if ($index === '' || $index === (string) $size) {
214+
if ($index === '' || $index === (string) $size) { // append
211215
$redis->rPush($key, $value);
212-
} elseif ($index === '-1') {
216+
} elseif ($index === '-1') { // prepend
213217
$redis->lPush($key, $value);
214218
} elseif ($index >= 0 && $index < $size) {
215219
$redis->lSet($key, (int) $index, $value);
@@ -229,6 +233,9 @@ private function saveKey(Redis $redis): void {
229233

230234
$redis->hSet($key, Http::post('hash_key'), $value);
231235
break;
236+
case 'stream':
237+
$redis->xAdd($key, Http::post('stream_id', 'string', '*'), [Http::post('field') => $value]);
238+
break;
232239
default:
233240
}
234241

0 commit comments

Comments
 (0)