4

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This seems to be the acceptable answer, sadly; I will wait a day or two before accepting it, just in case... Thank you
Unfortunately symfony’s cache adapter interface just simply doesn’t allow for this kind of behavior. Nothing is stopping you from extending it for you application though I suppose...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.