-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Use the jgaskins/redis shard #98
Conversation
github: jgaskins/redis | ||
branch: master |
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 been working with @jgaskins on this, and there's still a few small things being updated before the next release. This will need to wait until the next release before being locked down.
@@connection ||= ::Redis::PooledClient.new url: Mosquito.configuration.redis_url | ||
@@connection ||= ::Redis::Client.new(URI.parse(Mosquito.configuration.redis_url.to_s)) |
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.
The Redis::Client
is pooled by default in this shard.
# nope, but flushdb should be ok... | ||
def self.flush : Nil | ||
redis.flushall | ||
# redis.flushall | ||
redis.flushdb |
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.
😬
Wow this is great. Thank you. I'm not opposed to this change, but it'll have to be a major point release so it doesn't nuke anyone that might depend on using the stefanwillie shard for some other uses. The |
I think the best solution will be if mosquito will not directly depend on any of these shards. Backend implementation for And then something like this:
This will fix the main issue that they both can't exist in the same project at the same time. |
@mamantoha I agree. I toyed around with that idea in #94. It's not untenable, but it's fiddly and excessively verbose. Crystal doesn't really have good tooling around this problem. If a clamor of folks that must use stefanwillie/redis or else they'd need to pay a cost of hundreds of man hours to switch existed, I think it would be worth exploring. That's why this proposal exists, to solicit feedback from anyone who is willing to participate. |
@robacarp I'm ok with the current dependency on |
Ah, yeah, that's the tricky part. If you have other projects that also depend on the I'd imagine if we went the other route, then Mosquito wouldn't be able to include any redis shard at all in the project. This means that any spec testing this stuff would all have to be mocked through an interface. Then there would need to be another shard created like With that said, it's not a bad thing to go that route, but I think more of a time/energy constraint. I have to deploy to production today, so I'll be using my fork regardless. Maybe someone would be willing to tackle that approach? I'd be cool with that too. |
@mamantoha Thanks for the context. It's complicated for sure. Would you mind sharing the dependencies which you have that also depend on stefan's redis? |
@robacarp https://github.com/neovintage/kemal-session-redis It's a pretty simple library. So in case, you will accept this PR I prefer to maintain a fork of |
@robacarp FYI. You can check all repositories dependent on |
Just adding some clarifications (and following the OLD/NEW convention in this PR for consistency):
I worked with the Crystal core team to make The simplicity of
TIL OLD Redis isn't self-healing. Applications shouldn't have to micromanage encapsulated TCP connections being severed and, after a cursory read through the pertinent parts of the code, I'm not sure that's something you can do at all with that client. I also can't find a way for OLD Redis's I've seen so many disconnections with both ElastiCache and Heroku Redis in the past that I find it odd that this hasn't come up more with that shard.
This can be streamlined in NEW Redis trivially. It likely just needs some type overrides added in The |
This is the direction for mosquito to go in. I'd like to see jgaskins/redis#32 go in first, because the @mamantoha I appreciate that this will put you in a position to fork, modify and/or maintain the Kemal session shard, and I'm sorry that is the case. As you said, the library complexity is an order of magnitude less. My intent is that the second version of mosquito (i.e. v1.0.0) can launch with jgaskins redis, but the rc1 will continue to point at stefanwillie's implementation. |
@robacarp It'll be no problem at all, believe me. |
FYI this has been merged in #106 |
This PR doesn't change any sort of logic, but just the underlying shard from
stefanwille/crystal-redis
(OLD Redis) tojgaskins/redis
(NEW Redis).I believe the idea of #94 would be to allow you to choose which one of these (or other future implementations) you wanted to use, but I ran in to some issues which I decided to just pull the trigger and do the conversion.
Here's the main tricky points to why I needed this change for my app, and maybe others would too.
class Redis
for the namespace, but NEW redis usesmodule Redis
for the namespace. This causes a collision meaning they both can't exist in the same project at the same time even as sub-dependencies of shards you can't control. If Cable CR moves to NEW Redis, then all apps using both Mosquito, and Cable will instantly break.The only major downside I've ran in to is OLD Redis was really nice about "This returned a String, so here's a String"... NEW Redis has this Value that is a recursive alias. This makes casting things a little harder since you don't quite know what something is which is why there's a lot of
.as(Something)
....EDIT: Before switching to this PR, I was having to reboot my app daily due to dropped redis connections with OLD redis. Using this PR and NEW Redis, in production, it's been a few days with no issues.