How to use redis-mock - 10 common examples

To help you get started, we’ve selected a few redis-mock 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 Cimpress-MCP / deployment-tracker / lib / redis.js View on Github external
module.exports.init = function(config) {
  try {

    var redisClient;
    if (process.env.DEPLOYMENT_TRACKER_MOCK_REDIS || "" !== "") {
      var MockRedis = require("redis-mock");
      redisClient = MockRedis.createClient();
    } else {
      var Redis = require("ioredis");
      redisClient = new Redis(config);
    }

    redisClient.on("connect", function() {
        logger.info("connected to redis");
    });

    redisClient.on("error", function (err) {
      logger.error(err, "Error caught from redis_client.");
    });

    redisClient.key = config.key || "logstash";

    // Add index and addtional_fields to the log message and return it
github RasCarlito / axios-cache-adapter / test / spec / redis.spec.js View on Github external
describe('Redis store', () => {
  let store
  const client = redis.createClient()

  beforeEach(() => {
    store = new RedisStore(client)
  })

  it('Should throw error if redis client is not valid', async () => {
    assert.throws(() => new RedisStore(null))
    assert.throws(() => new RedisStore({ constructor: null }))
    assert.throws(() => new RedisStore({ constructor: { name: 'MongoClient' } }))
  })

  it('Should accept custom HASH_KEY', async () => {
    const expected = 'customHash'
    store = new RedisStore(client, expected)
    assert.equal(store.HASH_KEY, expected)
  })
github jonniespratley / jps-passbook-manager / test / specs / redis-spec.js View on Github external
before(function() {
			client = redis.createClient();
			db = new RedisDB({
				client: client
			});
		});
github teamplanes / graphql-rate-limit / src / lib / redis-store.spec.ts View on Github external
test('RedisStore sets and gets correct timestamps', async t => {
  const storeInstance = new RedisStore(redis.createClient());

  await storeInstance.setForIdentity(
    { contextIdentity: 'foo', fieldIdentity: 'bar' },
    [1, 2, 3]
  );
  t.deepEqual(
    await storeInstance.getForIdentity({
      contextIdentity: 'foo',
      fieldIdentity: 'bar'
    }),
    [1, 2, 3]
  );

  await storeInstance.setForIdentity(
    { contextIdentity: 'foo', fieldIdentity: 'bar2' },
    [4, 5]
github microsoft / opensource-portal / middleware / initialize.ts View on Github external
var redisOptions : RedisOptions = {
    auth_pass: config.redis.key,
    detect_buffers: true,
  };
  if (config.redis.tls) {
    redisOptions.tls = {
      servername: config.redis.tls,
    };
  }
  if (!config.redis.host && !config.redis.tls) {
    if (nodeEnvironment === 'production') {
      console.warn('Redis host or TLS host must be provided in production environments');
      throw new Error('No config.redis.host or config.redis.tls');
    }
    debug(`mocking Redis, in-memory provider in use`);
    redisClient = redisMock.createClient();
  } else {
    debug(`connecting to Redis ${config.redis.host || config.redis.tls}`);
    const port = config.redis.port || (config.redis.tls ? 6380 : 6379);
    redisClient = redis.createClient(port, config.redis.host || config.redis.tls, redisOptions);
  }
  const redisHelper = new RedisHelper(redisClient, config.redis.prefix);
  app.set('redisHelper', redisHelper);
  providers.redis = redisHelper;
  redisClient.on('connect', function () {
    if (redisFirstCallback) {
      var cb = redisFirstCallback;
      redisFirstCallback = null;
      cb();
    }
  });
github microsoft / opensource-portal / middleware / initialize.ts View on Github external
auth_pass: wr.key,
      detect_buffers: true,
    };
    if (wr.tls) {
      witnessRedisOptions.tls = {
        servername: wr.tls,
      };
    }
    wr.port = wr.port || (wr.tls ? 6380 : 6379);
    if (!wr.host && !wr.tls) {
      if (nodeEnvironment === 'production') {
        console.warn('Redis host or TLS host must be provided in production environments');
        throw new Error('No wr.host or wr.tls');
      }
      debug(`mocking Witness Redis, in-memory provider in use`);
      providers.witnessRedis = redisMock.createClient();
    } else {
      debug(`connecting to Witness Redis ${wr.host || wr.tls}`);
      providers.witnessRedis = redis.createClient(wr.port, wr.host || wr.tls, witnessRedisOptions);
    }
    providers.witnessRedisHelper = new RedisHelper(providers.witnessRedis);
  }

  async.parallel([
    function (cb) {
      redisFirstCallback = cb;
      redisClient.auth(config.redis.key);
      debug('authenticated to Redis');
    },
    function createMailAddressProvider(next) {
      const options = {
        config: config,
github kinecosystem / marketplace-server / scripts / src / redis.ts View on Github external
export function getRedisClient(): RedisAsyncClient {
	if (!client) {
		if (getConfig().redis === "mock") {
			isMocked = true;
			client = require("redis-mock").createClient();
		} else {
			client = require("redis").createClient(getConfig().redis);
		}
		client.async = {} as RedisAsyncFunctions;
		["get", "mget", "set", "setex", "del", "incrby"].forEach(name => {
			(client.async as any)[name] =  promisify((client as any)[name]).bind(client);
		});
	}

	return client;
}
github shalvah / RemindMeOfThisTweet / spec / support / mocks.js View on Github external
const mockCache = () => {
    const redis = require("redis-mock");
    require('bluebird').promisifyAll(redis.RedisClient.prototype);
    const cache = redis.createClient();
    mock("../../src/cache", cache);
    return cache;
};
github shalvah / DownloadThisVideo / spec / support / mocks.js View on Github external
const mockCache = () => {
    const redis = require("redis-mock");
    require('bluebird').promisifyAll(redis.RedisClient.prototype);
    const cache = redis.createClient();
    mock('../../src/services/cache', cache);
    return cache;
};
github shalvah / RemindMeOfThisTweet / spec / support / mocks.js View on Github external
const mockCache = () => {
    const redis = require("redis-mock");
    require('bluebird').promisifyAll(redis.RedisClient.prototype);
    const cache = redis.createClient();
    mock("../../src/cache", cache);
    return cache;
};

redis-mock

Redis client mock object for unit testing

MIT
Latest version published 4 years ago

Package Health Score

59 / 100
Full package analysis