Redis Mutator
GitHub
Inject another Redis connection to your Redis connection!
Installation
pip install redis-mutator
Uses
- Separate read-only functions to another Redis connection.
- Log functions as you use them.
How to Use
from redis_mutator import mutate, READ_METHOD_NAMES
from redis import Redis
redis = Redis(...)
read_only_redis = Redis(...)
mutate(redis, READ_METHOD_NAMES).use(read_only_redis)
redis.sadd("hello", "world!")
redis.smembers("hello")
Specify Method Names
from redis_mutator import mutate
from redis import Redis
redis = Redis(...)
my_other_redis = Redis(...)
mutate(redis, "sadd", "spop").use(my_other_redis)
redis.sadd("hello", "world!")
redis.spop("hello", 1)
redis.hset("hello", "world", "hi")
redis.hget("hello", "world")
Prefix & Postfix Hooks
from redis_mutator import mutate
from redis import Redis
redis = Redis(...)
my_other_redis = Redis(...)
def prefix(*args, **kwargs):
print('Prefix called.')
def postfix(value):
print('Postfix called.')
mutate(redis, "sadd", "spop").prefix(prefix)
mutate(redis, "sadd", "spop").postfix(postfix)
redis.sadd("hello", "world!")
Override Methods
from redis_mutator import mutate
from redis import Redis
redis = Redis(...)
my_other_redis = Redis(...)
def prefix(*args, **kwargs):
print('Hi-jacked!')
return False
mutate(redis, "sadd", "spop").prefix(prefix)
redis.sadd("hello", "world!")