@@ -583,14 +583,26 @@ def hmget(self, hashkey, keys, *args):
583583 attributes = self ._list_or_args (keys , args )
584584 return [self ._decode (redis_hash .get (self ._encode (attribute ))) for attribute in attributes ]
585585
586- def hset (self , hashkey , attribute , value ):
586+ def hset (self , hashkey , attribute = None , value = None , mapping = None ):
587587 """Emulate hset."""
588+ if attribute is None and not mapping :
589+ raise DataError ("'hset' with no key value pairs" )
588590
589591 redis_hash = self ._get_hash (hashkey , 'HSET' , create = True )
590- attribute = self ._encode (attribute )
591- attribute_present = attribute in redis_hash
592- redis_hash [attribute ] = self ._encode (value )
593- return long (0 ) if attribute_present else long (1 )
592+ if attribute is not None :
593+ attribute = self ._encode (attribute )
594+ attribute_present = attribute in redis_hash
595+ redis_hash [attribute ] = self ._encode (value )
596+ return long (0 ) if attribute_present else long (1 )
597+
598+ elif mapping :
599+ created = long (0 )
600+ for attr , val in mapping .items ():
601+ attr = self ._encode (attr )
602+ attribute_present = attr in redis_hash
603+ redis_hash [attr ] = self ._encode (val )
604+ created += 0 if attribute_present else 1
605+ return created
594606
595607 def hsetnx (self , hashkey , attribute , value ):
596608 """Emulate hsetnx."""
0 commit comments