-
-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Success count now gets cleared when using Redis #74
Conversation
Thank you for this PR! I'll have a look and test this PR on this weekend. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for replying so late. 🙇
I think it is better to make changes only in the Redis Adapter, not adding abstract method to AdapterInterface. 💡
As we discussed here, zAdd does not allow to set an expire value, then we should remove expired elements explicitly.
However, there are cases in which the remove is unnecessary: using storages which allows expire value (e.g. memcached), or using Count strategy.
I think it is better to make changes only in the Redis Adapter. By doing so we can avoid adding methods to Adapters that we do not need to implement.
Hi, thanks for the reply and don't worry, hope everything is ok! I get what you are saying, but I don't know the correct way of implementing it. I guess that, since only Storage has access to the adapter, something like this should be done (?): public function clearSuccessCount(string $service): void
{
if ($this->adapter instanceof Redis) {
$this->adapter->removeExpiredElements($this->successKey($service));
}
} Because we have to control whether or not the adapter has the removeExpiredElements method before calling it, obviously. Is there a cleaner/better way to do so? I don't know, maybe adding a new method that works similarly to the supportCountStrategy method, and maybe allowing to set if to Waiting for your response. Once I get it back, I will try to modify the PR ASAP to satisfy the requirements. Thank you and stay safe! |
@ariasmn I'm sorry I didn't explain it enough. 🙇 My idea is that removing the expired values (zRemRangeByScore) in It is similar to the implementation you have shown here, it runs Thank you for your sincere response. Please let me know if you have any questions. ✨ |
Moved the code used to remove expired elements from the 'load' method to the 'increment' method.
@ackintosh Thank you, everything is clear now! I have updated the PR to meet the requeriments you pointed (truth be told, is way cleaner now). If anything should be done before merging the PR, please hit me up and I will try my best to do it as fast as I can. |
https://github.com/ackintosh/ganesha/pull/74/checks?check_run_id=2545653270
Oh, the CI failure is due to lack of adapter setup in unit tests. 👀
Setting up Redis adapter with calling + $redis = new Redis(($r));
+ $context = /* *** */
+ $redis->setContext($context);
+ $storage = new Storage($redis, new Ganesha\Storage\StorageKeys(), null);
- $storage = new Storage(new Redis(($r)), new Ganesha\Storage\StorageKeys(), null); |
See #74 for more info.
@ackintosh Woops, my bad. Tests are fixed now and they passed locally. If anything is wrong, please just tell me! |
Thank you! I'm checking the adapter manually using the example scripts. Please give me some time. 🙏 |
Hmm... I've found out that when a remote service can not respond any request, success count is not cleared (due to So we need to clear expired values also in Sorry for my mistake. 😓 |
Added use of case test. See #74.
@ackintosh No problem. Also my bad, didn't even realize that while testing the new implementation 😓 Tell me if anything else should be done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've confirmed that the adapter works fine!
I've add your company to the list. ✨ Thank you so much! |
Implemented only for the Redis adapter. Others adapter's methods are empty.
The method gets called everytime
Ganesha::isAvailable()
, which was the wanted behaviour, but the cleanup wasn't being executed correctly.. When called, the method remove those elements in the success keys which were registered before the time set in thetimeWindow()
(so, keys created before now - timeWindow get removed).This change, as far as I can tell (correct me if I'm wrong), doesn't break the behaviour, neither the implementations with adapters other than the Redis one.