#NEWLINE# def set_object( cache , template , indexes , data ) : #NEWLINE# #INDENT# "Set an object in Redis using a pipeline.\n\n    Only sets the fields that are present in both the template and the data.\n\n    Arguments:\n        template: a dictionary containg the keys for the object and\n            template strings for the corresponding redis keys. The template\n            string uses named string interpolation format. Example:\n\n            {\n                'username': 'user:%(id)s:username',\n                'email': 'user:%(id)s:email',\n                'phone': 'user:%(id)s:phone'\n            }\n\n        indexes: a dictionary containing the values to use to cosntruct the\n            redis keys: Example:\n\n            {\n                'id': 342\n            }\n\n        data: a dictionary returning the data to store. Example:\n\n        {\n            'username': 'bob',\n            'email': 'bob@example.com',\n            'phone': '555-555-5555'\n        }\n\n    " #NEWLINE# with cache as redis_connection : #NEWLINE# #INDENT# pipe = redis_connection . pipeline ( ) #NEWLINE# for key in ( set ( template . keys ( ) ) & set ( data . keys ( ) ) ) : #NEWLINE# #INDENT# pipe . set ( ( template [ key ] % indexes ) , str ( data [ key ] ) ) #NEWLINE# #UNINDENT# pipe . execute ( )