Replies: 2 comments 1 reply
-
Hey @kristos80, It is always great to hear someone using your packages. Had a quick look and I assume this is about Redis tags mentioned here, correct? https://redis.io/docs/stack/search/reference/tags/ Honestly, this sounds like a great feature to add, and I gladly add it to my packages. From a users POV how would you use this? |
Beta Was this translation helpful? Give feedback.
-
Hi @WyriHaximus, Thanks for getting back and believe me I cannot stretch enough how reactphp has helped me the last months with my project (I'll come back when I am done with a use case on how we are using reactphp to migrate a system from node.js to php). About the feature, now. No, I am talking about Redis tags --in fact I didn't know about it until now--, but rather for a tagging system for invalidating cache items like PHP-Cache does: https://www.php-cache.com/en/latest/#tagging For example the key Now, imagine that I've just updated the table So the cache pool would search for all the keys associated with that tag and delete them in its usual way. In PHP-Cache the tagging doesn't happen in the $item = $pool->getItem('tobias');
$item->set('value')->setTags(['tag0', 'tag1'])
$pool->save($item); In my project I have created a thin wrapper for your cache and have a $this->redisCache->set($key, $value, $ttl);
foreach ($tags as $tag) {
// Here tag can be normalized in order to avoid conflicts with other key names
$this->redisClient->rpush($tag, $key);
} In my wrapper I have a method as such: public function invalidateTags(array $tags): void {
foreach ($tags as $tag) {
$listLength = (int) \React\Async\await($this->redisClient->llen($tag));
if (! $listLength) {
continue;
}
$index = 0;
while($index < $listLength) {
$key = \React\Async\await($this->redisClient->lpop($tag));
$this->redisCache->delete($key);
$index++;
}
$this->redisClient->del($tag);
}
} I am not sure if that's an elegant or even a robust solution, but for now this is how I solve this need of mine, while being able if you update your library with a tagging system to adapt easily. Thanks again for your time! |
Beta Was this translation helpful? Give feedback.
-
First of all a big "thank you" to all code contributors.
Until recently I was using https://github.com/clue/reactphp-redis in order to create key value pairs in my application which was more than enough.
At some point I needed to implement a more sophisticated invalidation strategy for those keys (eg invalidate all database results from the same table if something is created/updated) which had as a result to go by https://github.com/WyriHaximus/reactphp-cache-redis which implements the https://github.com/reactphp/cache interface, but to my surprise I found out that tags are not supported.
I am not implying that support for tags is something trivial and easy to implement --especially in an asynchronous environment--, but it would be a really great feature.
Thanks again for all the effort you have put in this great project.
Beta Was this translation helpful? Give feedback.
All reactions