How to use the ioredis.createClient function in ioredis

To help you get started, we’ve selected a few ioredis 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 socketio / socket.io-redis / test / ioredis.js View on Github external
function create(nsp, fn){
    var srv = http();
    var sio = io(srv);
    sio.adapter(adapter({
      pubClient: redis(),
      subClient: redis(null, null, { return_buffers: true }),
      subEvent: 'messageBuffer'
    }));
    srv.listen(function(err){
      if (err) throw err; // abort tests
      if ('function' == typeof nsp) {
        fn = nsp;
        nsp = '';
      }
      nsp = nsp || '/';
      var addr = srv.address();
      var url = 'http://localhost:' + addr.port + nsp;
      fn(sio.of(nsp), ioc(url));
    });
  }
github microsoft / devops-project-samples / node / express / kubernetes / Application / routes / index.js View on Github external
'use strict';
var express = require('express');
var router = express.Router();
var redis = require('ioredis');

var redisServer = process.env.redis_server || 'redis-cache';

console.log("Trying to create redis client");
var client = redis.createClient(6379, redisServer);

console.log("Redis Client created");

/* GET home page. */
router.get('/', function (req, res) {
  console.log("Index route");
  client.incr('viewCount', function (err, result) {
    res.render('index', { message: "Total Visits: " + result });
  });
});

module.exports = router;
github mcollina / mosca / test / persistence / redis_spec.js View on Github external
this.instance.storeSubscriptions(client, function() {

      var redisClient = redis.createClient();
      redisClient.select(opts.db);
      redisClient.exists(redisClientSubscriptionKey, function(err, existence) {
        expect(!!existence).to.eql(true);
        redisClient.quit(done);
      });
    });
  });
github koajs / redis-session-sets / __tests__ / store.js View on Github external
'use strict'

const redis = require('ioredis')
const assert = require('assert')
const _ = require('lodash')

const Store = require('../lib/store')

const client = redis.createClient()

describe('Store', () => {
  const store = createStore({
    references: {
      user_id: true,
      ip: true
    }
  })
  let id

  it('should create a session id', () => {
    id = store.createSessionId()
    assert.equal('string', typeof id)
  })

  it('non-existent sessions should return an empty object', () => {
github mcollina / mosca / test / persistence / redis_spec.js View on Github external
function flush(cb) {
    var client = redis.createClient();
    client.select(opts.db);
    client.flushdb(function() {
      client.quit(cb);
    });
  }
github mcollina / mosca / test / persistence / redis_spec.js View on Github external
function flush() {
      var client = redis.createClient();
      client.flushdb(function() {
        client.quit(cb);
      });
    }
github instana / nodejs-sensor / test / tracing / database / ioredis / app.js View on Github external
tracing: {
    forceTransmissionStartingAt: 1
  }
});

var bodyParser = require('body-parser');
var express = require('express');
var morgan = require('morgan');
var redis = require('ioredis');
var request = require('request-promise');

var app = express();
var logPrefix = 'Express / Redis App (' + process.pid + '):\t';
var connectedToRedis = true;

var client = redis.createClient('//' + process.env.REDIS);

client.on('ready', function() {
  connectedToRedis = true;
});

if (process.env.WITH_STDOUT) {
  app.use(morgan(logPrefix + ':method :url :status'));
}

app.use(bodyParser.json());

app.get('/', function(req, res) {
  if (!connectedToRedis) {
    res.sendStatus(500);
  } else {
    res.sendStatus(200);
github actionhero / node-resque / __tests__ / utils / specHelper.ts View on Github external
connect: async function () {
    this.redis = Redis.createClient(this.connectionDetails.port, this.connectionDetails.host, this.connectionDetails.options)
    this.redis.setMaxListeners(0)
    if (this.connectionDetails.password !== null && this.connectionDetails.password !== '') {
      await this.redis.auth(this.connectionDetails.password)
    }
    await this.redis.select(this.connectionDetails.database)
    this.connectionDetails.redis = this.redis
  },
github koajs / redis-session-sets / __tests__ / index.js View on Github external
'use strict'

const _request = require('supertest')
const assert = require('assert')
const redis = require('ioredis')
const Koa = require('koa')

const Session = require('..')

const client = redis.createClient()
const keys = ['asdf', '1234']

beforeAll(() => client.flushall())

describe('context.session', () => {
  describe('should get and set the session', () => {
    const app = new Koa()
    app.keys = keys
    app.use(Session(app, {
      maxAge: '28 days',
      signed: false,
      prefix: 'asdf',
      references: {
        string: {}
      },
      client
github actionhero / node-resque / lib / connection.js View on Github external
this.connected = false
        this.emit('error', error)
      }
    }

    if (this.options.redis) {
      this.redis = this.options.redis
      await connectionTest()
    } else {
      if (this.options.pkg === 'ioredis') {
        const Pkg = require('ioredis')
        this.options.options.db = this.options.database
        this.redis = new Pkg(this.options.host, this.options.port, this.options.options)
      } else {
        const Pkg = require(this.options.pkg)
        this.redis = Pkg.createClient(this.options.port, this.options.host, this.options.options)
      }
    }

    this.listeners.error = (error) => { this.emit('error', error) }
    this.listeners.end = () => { this.connected = false }
    this.redis.on('error', this.listeners.error)
    this.redis.on('end', this.listeners.end)

    if (!this.options.redis) { await this.redis.select(this.options.database) }
    await connectionTest()
  }

ioredis

A robust, performance-focused and full-featured Redis client for Node.js.

MIT
Latest version published 1 year ago

Package Health Score

86 / 100
Full package analysis