hapijs / catbox-redis

Redis adapter for catbox
Other
69 stars 63 forks source link

Support `scaleReads` #119

Closed idahogurl closed 3 years ago

idahogurl commented 3 years ago

Support plan

Context

What problem are you trying to solve?

Our web site is having show-stopping performance issues and we are trying to setup a second Redis instance that is a read-only.

catbox-redis supports clusters but it does not support the Redis option of scaleReads. I found you closed #61 as you determined using a custom Redis client was sufficient. According to the documentation, a custom client must:

I was able to get the start to work but @hapijs/hapi handles all the situations where you'd need to stop/disconnect the Redis client. A custom client is not sufficient because of the manual stopping. Here is the code I have thus far with using a custom client. Here is what I have thus far.

https://gist.github.com/idahogurl/6f5acd5205c132089eea96fd055b092d

Do you have a new or modified API suggestion to solve the problem?

Yes, #78 was closed but it can be done differently. ioredis supports clusters and if you pass in scaleReads it will treat the first Redis node as the primary and then the other as secondaries. To have our setup for a readonly you set scaleReads to slave

Nargonath commented 3 years ago

If I understand correctly, you want the option scaleReads to be passed to redis from the plugin options, don't you? Does it need any further development from this plugin to use such option or just passing it solves your problem? If the latter, have you tried passing it already? From what I can see here: https://github.com/hapijs/catbox-redis/blob/8bb1c36750ff28c5dfa992de31b100b6d8745154/lib/index.js#L41 unknown keys are allowed in the Joi schema so you should be able to provide options that are not mentioned in catbox-redis documentation.

idahogurl commented 3 years ago

@Nargonath Thanks for the reply! I'll try it again. I attempted without and I got a validation error.

idahogurl commented 3 years ago

@Nargonath I tried with the latest package and it did work. Unfortunately we are not using @hapi/hapi@20. I cloned this repository and did a yarn link. It fails to connect but according to this https://github.com/luin/ioredis/issues/1003 I have to be on the EC2 box. I will mark the issue as closed. We will have to do some upgrades. Thank you!!

Nargonath commented 3 years ago

You're welcome @idahogurl . I'm glad I could help. 😉