diff options
| author | 2020-05-16 20:22:05 +0200 | |
|---|---|---|
| committer | 2020-05-16 20:22:05 +0200 | |
| commit | 588521c82403f6d66693512c6d33272cc370d755 (patch) | |
| tree | e53f80dfdcac85822331713ddcffa1982df3d764 /tests/test_helpers.py | |
| parent | Boilerplate for the RedisCacheMixin (diff) | |
Refactor - no more mixins!
It was brought to my attention that we may need several caches per Cog
for some of our Cogs. This means that the original approach of having
this be a mixin is a little bit problematic.
Instead, RedisDict will be instantiated directly inside the class you
want it in. By leveraging __set_name__, we can create a namespace
containing both the class name and the variable name without the user
having to provide anything.
For example, if you create an attribute MyClass.cache = RedisDict(),
this will be using the redis namespace 'MyClass.cache.' before anything
you store in it.
With this approach, it is also possible to instantiate a RedisDict with
a custom namespace by simply passing it into the constructor.
- RedisDict("firedog") will create items with the 'firedog.your_item'
prefix.
- If there are multiple RedisDicts using the same namespace, an
underscore will be appended to the namespace, such that the second
RedisDict("firedog") will actually create items in the
'firedog_.your_item' namespace.
This is also possible to use outside of classes, so long as you provide
a custom namespace when you instantiate it.
Custom namespaces will always take precedence over automatic
'Class.attribute_name' ones.
Diffstat (limited to 'tests/test_helpers.py')
0 files changed, 0 insertions, 0 deletions