I am unsure about where would be the best place to define the redis client in a Express application I am building. I am using skeleton as the framework.

It seems like the connection to redis should go in either boot.coffee or app.coffee, but then I can't easily get a reference to it in application_controller.coffee, which is where I need it.

If I put client = redis.createClient in application_controller.coffee, will that mean a new client is created on each request?

有帮助吗?

解决方案

I would define the Redis client in app.coffee (after configuration, before the routes) and set the Redis client as a property on the App object: app.client = redis.createClient

Then in application_controller.coffee you can access the Redis client by app.client.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top