I'm using Symfony RedisAdapter
in a project in order to handle cached values, and it's already deeply used inside the project.
Now I would like to add new redis keys which store some numerical counts, which can be updated very often. So I want to use INCR
and DECR
redis commands in order to do it fast.
But the RedisAdapter
don't seem to allow custom redis commands, you can only fetch, check key existence, delete and save keys. Of course I could fetch the count value, increment it in php, then save it again, but it's not very optimized considering that there is already a solution implemented in redis for this.
Is it possible to run custom redis commands, while keeping the redis abstraction layer offered by Symfony?
Unfortunately Symfony's redis adapter doesn't allow for this functionality, as it's nothing something that would be shared between the rest of symfony's caching adapters. You'd need to access the underlying redis client the adapter is using and use it to make the call you'd like. For instance with predis:
$predis = new Predis\Client(/* Configuration */);
$predis->incr($my_key);
Obviously this is far from ideal as one is now tying their coupling their application to Redis and whatever Redis client is being used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With