2.0.0 • Published 5 years ago

corie-redis-client v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

corie-redis-client

npm package

Note: ioredis pool


Table of contents


Installation

npm install --save corie-redis-client

# or

cnpm install --save corie-redis-client

Usage

'use strict';

const RedisPool = require('corie-redis-client');

const pool = new RedisPool({
  redis: {
    port: 6379,          // Redis port
    host: '127.0.0.1',   // Redis host
    password: 'auth'
  },
  pool: {
    min: 2,
    max: 10
  }
});

async function todo() {
  let client;
  try {

    // get a connection for redis
    client = await pool.getConnection();

    // save something to redis
    client.set('test', 'test redis');

    // get something from redis
    const result = await client.get('test');
    console.log('saved successfully', result);

    // delete something from redis
    client.del('test');
    console.log('deleted successfully', result);

  } catch (e) {

    // caught an error
    console.error(e);

  } finally {

    // finally release redis client to pool
    if (client) {
      await pool.release(client);
      console.log('released');
    }

  }

  // close connection with redis
  await pool.end();
  console.log('closed');
}

todo();

Examples

2.0.0

5 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago