简体   繁体   中英

How to properly set up a native redis connection for a Sails application?

I'd like to use redis connections for my sails application but I dont want to use sail-redis as I won't bind it to any model.

So I identify what steps I should follow.

  1. Connect Redis using any node adapter. This probably should be done at bootstrap sails process.
  2. Expose Redis globally and/or bind it to a Service.

Then I get quite confused as I don't really know how to expose any object globally and, in case I need it, prepare functions using redis and binding to any custom service.

How can I achieve it?

You could attach your Redis adapter to the sails object in the bootstrap

// config/bootstrap.js
sails.redis = your_redis_adapter

The sails object being accessible globally, you will be able to access to the redis adapter from any point of your application too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM