-
Notifications
You must be signed in to change notification settings - Fork 208
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
Will timeouts be considered to adding to the repo? #13
Comments
The primary use case for miniredis is unittests, in which case timeouts are not wanted. I do want to test if timeouts are set correctly, but the timeouts shouldn't trigger. So I prefer to keep them as is. What's your use case for the timeouts? |
Thanks for your reply. Currently I'm using Redis to implement a rate-limiting service, and trying to cover all the functionalities by unittests. And till now, only the expire part cannot be covered when using miniredis as a mock. Do you have any suggestions? |
I see you point, I'll think about it. It would certainly be optional behavior. |
Yes, and I'm thinking about adding this feature in my fork, my current idea is to add a periodic timer to trigger key deletion in the DB. How do you like it? |
The more I think about it the more I would make a sort of fast-forward, time-machine function. You call it with a duration, and all TTLs timeouts will be decreased by that much, and any expired keys will be deleted. In this way you then have full control in your tests over how 'fast' time goes. You can do things like:
Or you can call it in a quick loop in your test, if you want more real-time like behavior. I think having a system which is paused by default and only moves when you tell it to should work good for testing. And as a bonus you won't need to call Some things to consider:
How about this way, Sun? |
Hi Harmen, I like the idea of time machine, and for mock redis, the time manipulation be as flexible as possible. And If I understand your idea correctly, it should be somewhat like #14 (could you help to review it? Thanks! ). Regarding your concerns, I think for unit test, durations should work fine. And I agree that TTL values can be extended with units (seconds, milliseconds, etc). |
Looks good as the general idea. Would it be useful this way in the mixer project? |
Thanks, and yes, it is useful for the unit test of our redis-based rate-limiter. And would you like to merge the PR in? If so, I will make it more complete. |
Yeah, I would like to merge it. |
Awesome, I will update the PR, and your comments would be a lot of help. |
I pulled your branch into the Does this now work for you? If so I'll merge this into master and call it 2.0. |
It's merged, let me know if there are any issues! |
And thanks for the help! |
Yes, it looks great! Thank you! |
I found that timeout are not implemented, is there any plan to implement it? And is there any technical challenge in the implementation? Do you accept the contribution from outside?
Thank you!
The text was updated successfully, but these errors were encountered: