@@ -739,10 +739,10 @@ public function hmget($key, $fields)
739
739
return $ this ->returnPipedInfo ($ result );
740
740
}
741
741
742
- public function hdel ($ key , $ field )
742
+ public function hdel ($ key , $ fields )
743
743
{
744
744
if (func_num_args () > 2 ) {
745
- throw new UnsupportedException ('In RedisMock, `hdel` command can not delete more than one entry at once . ' );
745
+ throw new UnsupportedException ('In RedisMock, `hdel` command does not accept more than two arguments . ' );
746
746
}
747
747
748
748
if (isset (self ::$ dataValues [$ this ->storage ][$ key ]) && !is_array (self ::$ dataValues [$ this ->storage ][$ key ])) {
@@ -753,16 +753,21 @@ public function hdel($key, $field)
753
753
return $ this ->returnPipedInfo (0 );
754
754
}
755
755
756
- if (array_key_exists ($ field , self ::$ dataValues [$ this ->storage ][$ key ])) {
757
- unset(self ::$ dataValues [$ this ->storage ][$ key ][$ field ]);
758
- if (0 === count (self ::$ dataValues [$ this ->storage ][$ key ])) {
759
- unset(self ::$ dataTypes [$ this ->storage ][$ key ]);
760
- }
756
+ $ fields = is_array ($ fields ) ? $ fields : [$ fields ];
757
+ $ info = 0 ;
761
758
762
- return $ this ->returnPipedInfo (1 );
763
- } else {
764
- return $ this ->returnPipedInfo (0 );
759
+ foreach ($ fields as $ field ) {
760
+ if (array_key_exists ($ field , self ::$ dataValues [$ this ->storage ][$ key ])) {
761
+ unset(self ::$ dataValues [$ this ->storage ][$ key ][$ field ]);
762
+ if (0 === count (self ::$ dataValues [$ this ->storage ][$ key ])) {
763
+ unset(self ::$ dataTypes [$ this ->storage ][$ key ]);
764
+ }
765
+
766
+ $ info ++;
767
+ }
765
768
}
769
+
770
+ return $ this ->returnPipedInfo ($ info );
766
771
}
767
772
768
773
public function hkeys ($ key )
0 commit comments