@@ -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