Set an object in Redis using a pipeline.

    Only sets the fields that are present in both the template and the data.

    Arguments:
        template: a dictionary containg the keys for the object and
            template strings for the corresponding redis keys. The template
            string uses named string interpolation format. Example:

            {
                'username': 'user:%(id)s:username',
                'email': 'user:%(id)s:email',
                'phone': 'user:%(id)s:phone'
            }

        indexes: a dictionary containing the values to use to cosntruct the
            redis keys: Example:

            {
                'id': 342
            }

        data: a dictionary returning the data to store. Example:

        {
            'username': 'bob',
            'email': 'bob@example.com',
            'phone': '555-555-5555'
        }

def set_object(cache, template, indexes, data):
    """Set an object in Redis using a pipeline.

    Only sets the fields that are present in both the template and the data.

    Arguments:
        template: a dictionary containg the keys for the object and
            template strings for the corresponding redis keys. The template
            string uses named string interpolation format. Example:

            {
                'username': 'user:%(id)s:username',
                'email': 'user:%(id)s:email',
                'phone': 'user:%(id)s:phone'
            }

        indexes: a dictionary containing the values to use to cosntruct the
            redis keys: Example:

            {
                'id': 342
            }

        data: a dictionary returning the data to store. Example:

        {
            'username': 'bob',
            'email': 'bob@example.com',
            'phone': '555-555-5555'
        }

    """
    # TODO(mattmillr): Handle expiration times
    with cache as redis_connection:
        pipe = redis_connection.pipeline()
        for key in set(template.keys()) & set(data.keys()):
            pipe.set(template[key] % indexes, str(data[key]))
        pipe.execute()