I'm working with a redis database and I'd like to integrate my prototype code to my baseline as seamlessly as possible so I'm trying to bury most of the inner workings with the interface from the python client to the redis server code into a few base classes that I will subclass throughout my production code.
I'm wondering if the assignment operator in python =
is a callable and whether if it possible to modify the callable's pre and post behavior, particularly the post behavior such that I can call object.save()
so that the redis cache would be updated behind the scenes without having to explicitly call it.
For example,
# using the redis-om module
from redis_om import JsonModel
kwargs = {'attr1': 'someval1', 'attr2': 'someval2'}
jsonModel = JsonModel(**kwargs)
# as soon as assignment completes, redis database
# has the new value updated without needing to
# call jsonModel.save()
jsonModel.attr1 = 'newvalue'