How to use the actionhero.api.redis function in actionhero

To help you get started, we’ve selected a few actionhero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github actionhero / actionhero-angular-bootstrap-cors-csrf / initializers / session.js View on Github external
async initialize () {
    const redis = api.redis.clients.client

    api.session = {
      prefix: 'session:',
      ttl: 60 * 60 * 24, // 1 day

      load: async (connection) => {
        const key = api.session.prefix + connection.fingerprint

        const data = await redis.get(key)
        if (!data) { return false }
        return JSON.parse(data)
      },

      create: async (connection, user) => {
        const key = api.session.prefix + connection.fingerprint
        const randomBuffer = await util.promisify(crypto.randomBytes)(64)
github actionhero / actionhero-tutorial / initializers / blog.js View on Github external
async initialize () {
    const redis = api.redis.clients.client

    api.blog = {
      separator: ';',
      postPrefix: 'posts',
      commentPrefix: 'comments:'
    }

    api.blog.postAdd = async (userName, title, content) => {
      const key = api.blog.buildTitleKey(userName, title)
      const data = {
        content,
        title,
        userName,
        createdAt: new Date().getTime(),
        updatedAt: new Date().getTime()
      }
github actionhero / actionhero-tutorial / initializers / users.js View on Github external
async initialize () {
    const redis = api.redis.clients.client

    api.users = {}

    api.users.add = async (userName, password) => {
      const savedUser = await redis.hget(this.usersHash, userName)
      if (savedUser) { throw new Error('userName already exists') }
      const hashedPassword = await api.users.cryptPassword(password)
      const data = {
        userName: userName,
        hashedPassword: hashedPassword,
        createdAt: new Date().getTime()
      }

      await redis.hset(this.usersHash, userName, JSON.stringify(data))
    }