@@ -4924,10 +4924,14 @@ public function testIntrospection() {
49244924
49254925 protected function get_keyspace_count ($ str_db ) {
49264926 $ arr_info = $ this ->redis ->info ();
4927- $ arr_info = $ arr_info [$ str_db ];
4928- $ arr_info = explode (', ' , $ arr_info );
4929- $ arr_info = explode ('= ' , $ arr_info [0 ]);
4930- return $ arr_info [1 ];
4927+ if (isset ($ arr_info [$ str_db ])) {
4928+ $ arr_info = $ arr_info [$ str_db ];
4929+ $ arr_info = explode (', ' , $ arr_info );
4930+ $ arr_info = explode ('= ' , $ arr_info [0 ]);
4931+ return $ arr_info [1 ];
4932+ } else {
4933+ return 0 ;
4934+ }
49314935 }
49324936
49334937 public function testScan () {
@@ -4962,6 +4966,48 @@ public function testScan() {
49624966 $ i -= count ($ arr_keys );
49634967 }
49644968 $ this ->assertEquals (0 , $ i );
4969+
4970+ // SCAN with type is scheduled for release in Redis 6.
4971+ if (version_compare ($ this ->version , "6.0.0 " , "gte " ) >= 0 ) {
4972+ // Use a unique ID so we can find our type keys
4973+ $ id = uniqid ();
4974+
4975+ // Create some simple keys and lists
4976+ for ($ i = 0 ; $ i < 3 ; $ i ++) {
4977+ $ str_simple = "simple: {$ id }: $ i " ;
4978+ $ str_list = "list: {$ id }: $ i " ;
4979+
4980+ $ this ->redis ->set ($ str_simple , $ i );
4981+ $ this ->redis ->del ($ str_list );
4982+ $ this ->redis ->rpush ($ str_list , ['foo ' ]);
4983+
4984+ $ arr_keys ["STRING " ][] = $ str_simple ;
4985+ $ arr_keys ["LIST " ][] = $ str_list ;
4986+ }
4987+
4988+ // Make sure we can scan for specific types
4989+ foreach ($ arr_keys as $ str_type => $ arr_vals ) {
4990+ foreach ([NULL , 10 ] as $ i_count ) {
4991+ $ arr_resp = [];
4992+
4993+ $ it = NULL ;
4994+ while ($ arr_scan = $ this ->redis ->scan ($ it , "* $ id* " , $ i_count , $ str_type )) {
4995+ $ arr_resp = array_merge ($ arr_resp , $ arr_scan );
4996+ }
4997+
4998+ sort ($ arr_vals ); sort ($ arr_resp );
4999+ $ this ->assertEquals ($ arr_vals , $ arr_resp );
5000+ }
5001+ }
5002+
5003+ // Make sure only lists come back even without a pattern or count
5004+ $ it = NULL ;
5005+ $ arr_scan = $ this ->redis ->scan ($ it , NULL , NULL , "LIST " );
5006+ foreach ($ arr_scan as $ str_key ) {
5007+ $ this ->assertEquals ($ this ->redis ->type ($ str_key ), Redis::REDIS_LIST );
5008+ }
5009+ }
5010+
49655011 }
49665012
49675013 public function testHScan () {
0 commit comments