main.ts 1.1 KB

12345678910111213141516171819202122232425262728
  1. /**
  2. * This is entry file when system running.
  3. * You can change in /config file
  4. */
  5. import { RedisClientType } from "@redis/client";
  6. /**
  7. * This one shows how to make a redis connection through database tookit.
  8. */
  9. /**
  10. * Function 'H' is a syntactic sugar to get util tools quickly.
  11. * It will find the tool library automatically in '/lib/helper' or '/app/lib/helper'.
  12. */
  13. export = {};
  14. declare const MainRedis:RedisClientType; //For typescript :(
  15. const DBManager = H('database'); //Get database manager tookit
  16. const redisOption:DBOption = DBManager.getOption('redis'); //Make default connect option for redis
  17. // redisOption.host = option.Redis.host; //You can edit the option
  18. // redisOption.port = option.Redis.port;
  19. DBManager.create('redis',redisOption,'MainRedis',async (err:Error,redisClient:RedisClientType)=>{ //Create a redis database connection & Set a global property named 'MainRedis' that you can use it everywhere,don't forget decalre.
  20. LOGGER.log('Test connect redis server'); //Global logger tookit,support [ log | info | debug | warn | error ] 5 levels
  21. const info = await MainRedis.info();
  22. LOGGER.debug(info);
  23. });