redis.mjs 989 B

123456789101112131415161718192021222324252627282930313233343536
  1. import redis from '@overleaf/redis-wrapper'
  2. import config from 'config'
  3. // Get allowed Redis dbs from config
  4. const redisConfig = config.get('redis')
  5. const allowedDbs = Object.keys(redisConfig)
  6. // Get the Redis db from command line argument or use the first available db as default
  7. const db = process.argv[2]
  8. // Validate redis db
  9. if (!allowedDbs.includes(db)) {
  10. if (db) {
  11. console.error('Invalid redis db:', db)
  12. }
  13. console.error(`Usage: node redis.mjs [${allowedDbs.join('|')}]`)
  14. process.exit(1)
  15. }
  16. // Get redis options based on command line argument
  17. const redisOptions = config.get(`redis.${db}`)
  18. console.log('Using redis db:', db)
  19. console.log('REDIS CONFIG', {
  20. ...redisOptions,
  21. password: '*'.repeat(redisOptions.password?.length),
  22. })
  23. const rclient = redis.createClient(redisOptions)
  24. try {
  25. await rclient.healthCheck()
  26. console.log('REDIS HEALTHCHECK SUCCEEDED')
  27. } catch (error) {
  28. console.error('REDIS HEALTHCHECK FAILED', error)
  29. } finally {
  30. await rclient.quit()
  31. }