@@ -143,14 +143,34 @@ public function pipelineKeys(array $keys): array {
143143
144144 foreach ($ keys as $ i => $ key ) {
145145 $ index = $ i * 3 ;
146-
147146 $ data [$ key ] = [
148- 'ttl ' => $ results [$ index ],
149- 'type ' => $ this ->getType ((string ) $ results [$ index + 1 ]),
150- 'size ' => is_int ($ results [$ index + 2 ]) ? $ results [$ index + 2 ] : 0 ,
147+ 'ttl ' => $ results [$ index ],
148+ 'type ' => (string ) $ results [$ index + 1 ],
149+ 'size ' => is_int ($ results [$ index + 2 ]) ? $ results [$ index + 2 ] : 0 ,
150+ 'count ' => null ,
151151 ];
152152 }
153153
154+ $ type_results = $ this ->pipeline (function ($ pipe ) use ($ keys , $ data ): void {
155+ foreach ($ keys as $ key ) {
156+ $ lua_script = match ($ data [$ key ]['type ' ]) {
157+ 'set ' => 'return redis.call("SCARD", KEYS[1]) ' ,
158+ 'list ' => 'return redis.call("LLEN", KEYS[1]) ' ,
159+ 'zset ' => 'return redis.call("ZCARD", KEYS[1]) ' ,
160+ 'hash ' => 'return redis.call("HLEN", KEYS[1]) ' ,
161+ 'stream ' => 'return redis.call("XLEN", KEYS[1]) ' ,
162+ default => 'return nil ' ,
163+ };
164+
165+ $ pipe ->eval ($ lua_script , 1 , $ key );
166+ }
167+ });
168+
169+ foreach ($ keys as $ i => $ key ) {
170+ $ type = $ data [$ key ]['type ' ];
171+ $ data [$ key ]['count ' ] = ($ type !== 'none ' && isset ($ type_results [$ i ]) && is_int ($ type_results [$ i ])) ? $ type_results [$ i ] : null ;
172+ }
173+
154174 return $ data ;
155175 }
156176
0 commit comments