{"size": 1399, "ext": "js", "max_stars_repo_path": "lib/redis.js", "max_stars_repo_name": "realglobe-Inc/pon-task-docker", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/redis.js", "max_issues_repo_name": "realglobe-Inc/pon-task-docker", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/redis.js", "max_forks_repo_name": "realglobe-Inc/pon-task-docker", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 17.2716049383, "max_line_length": 52, "alphanum_fraction": 0.5425303788}
/**
 * Run redis
 * @function redis
 * @param {string} name - Container name
 * @param {Object} [options={}] - Optional settings
 */
'use strict'

const adockerRedis = require('adocker-redis')
const asleep = require('asleep')

/** @lends redis */
function redis (name, options = {}) {
  const {
    conf=false,
    image = 'redis:latest',
    rootPassword = 'root',
    dataDir = 'var/redis',
    publish = false,
    network = 'default'
  } = options

  const {
    run,
    logs,
    start,
    hasContainer,
    isRunning,
    stop,
    remove,
    terminal
  } = adockerRedis(name, {
    conf,
    image,
    rootPassword,
    dataDir,
    publish,
    network
  })

  async function task (ctx) {
    return task.run(ctx)
  }

  Object.assign(task, {
    async run (ctx) {
      const {logger} = ctx
      if (await isRunning()) {
        logger.debug(`"${name}" is already running`)
        return
      }
      if (await hasContainer()) {
        await start()
      } else {
        await run()
      }
      // Wait for server to startup
      await asleep(3 * 1000)
    },
    async logs (ctx) {
      await logs()
    },
    async start (ctx) {
      await start()
    },
    async stop (ctx) {
      await stop()
    },
    async remove (ctx) {
      await remove({force: true})
    },
    async terminal (ctx) {
      await terminal()
    }
  })

  return task
}

module.exports = redis
