How to use ioredis-mock - 6 common examples

To help you get started, we’ve selected a few ioredis-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 dadi / cache / test / unit / redis.js View on Github external
sinon.test(function (done) {
        const client = new RedisMock()
        this.stub(noderedis, 'createClient').returns(client)
        // const spy = this.spy(client, 'set')

        let metadata = {
          foo: 'bar',
          baz: 123
        }

        cache = new Cache({
          directory: { enabled: false, path: './cache', extension: 'json' },
          redis: { enabled: true, host: '127.0.0.1', port: 6379 }
        })
        cache.set('key-string', 'data', { metadata }).then(() => {
          cache.getMetadata('key-string').then(metadata => {
            metadata.should.eql(metadata)
github dadi / cache / test / unit / redis.js View on Github external
const fs = require('fs')
const path = require('path')
const sinon = require('sinon')
const should = require('should')
const noderedis = require('redis')
const Stream = require('stream')
const toString = require('stream-to-string')
const RedisMock = require('ioredis-mock').default
const exec = require('child_process').exec
const EventEmitter = require('events').EventEmitter

const Cache = require('./../../lib/index')

/* RedisMock is not complete, so must create some stubs */
RedisMock.prototype.on = () => {}
RedisMock.prototype.status = 'ready'

var cache

describe('RedisCache', () => {
  describe('set', () => {
    after(done => {
      // remove cache folder contents completely, and recreate
      const cleanup = dir => {
        exec('rm -r ' + dir, (_, stdout, stderr) => {
          exec('mkdir ' + dir)
          done()
        })
      }

      if (cache.cacheHandler.directory) {
        cleanup(path.resolve(cache.cacheHandler.directory))
github dadi / cache / test / unit / redis.js View on Github external
const fs = require('fs')
const path = require('path')
const sinon = require('sinon')
const should = require('should')
const noderedis = require('redis')
const Stream = require('stream')
const toString = require('stream-to-string')
const RedisMock = require('ioredis-mock').default
const exec = require('child_process').exec
const EventEmitter = require('events').EventEmitter

const Cache = require('./../../lib/index')

/* RedisMock is not complete, so must create some stubs */
RedisMock.prototype.on = () => {}
RedisMock.prototype.status = 'ready'

var cache

describe('RedisCache', () => {
  describe('set', () => {
    after(done => {
      // remove cache folder contents completely, and recreate
      const cleanup = dir => {
        exec('rm -r ' + dir, (_, stdout, stderr) => {
          exec('mkdir ' + dir)
          done()
        })
      }

      if (cache.cacheHandler.directory) {
github stipsan / epic / test / testRedis.js View on Github external
// @TODO https://github.com/yarnpkg/yarn/issues/2266
//import bcrypt from 'bcrypt'
import bcrypt from 'bcryptjs'
import RedisMock from 'ioredis-mock'

const lastVisit = '2016-03-22T00:15:46.757Z'
const password = bcrypt.hashSync('batman', 10)

const testRedis = new RedisMock({
  data: {
    user_next: '5',
    secret: 'used in password hashing',
    emails: {
      'clark@daily.planet': '2',
      'bruce@wayne.enterprises': '3',
      'peter.parker@dailybugle.com': '4',
      'lex@lex.corp': '5',
    },
    'user:2': { id: '2', username: 'superman', online: '1', email: 'clark@daily.planet' },
    'user:3': { id: '3', username: 'batman', online: '1', email: 'bruce@wayne.enterprises', password },
    'user:4': { id: '4', username: 'spiderman', online: '0', email: 'peter.parker@dailybugle.com' },
    'user:5': { id: '5', username: 'lex', online: '0', email: 'lex@lex.corp', lastVisit },
    'games:3': [],
    'user:2:invites': [],
    'user:3:invites': ['4', '5'],
github dadi / cache / test / unit / redis.js View on Github external
sinon.test(function (done) {
        const client = new RedisMock()
        this.stub(noderedis, 'createClient').returns(client)
        const spy = this.spy(client, 'set')

        let metadata = {
          foo: 'bar',
          baz: 123
        }

        cache = new Cache({
          directory: { enabled: false, path: './cache', extension: 'json' },
          redis: { enabled: true, host: '127.0.0.1', port: 6379 }
        })
        cache.set('key-string', 'data', { metadata }).then(() => {
          spy.called.should.eql(true)
          spy.firstCall.args[0].indexOf('key-string').should.be.above(-1)
          spy.secondCall.args[0].should.eql('___key-string___')
github dadi / cache / test / unit / redis.js View on Github external
sinon.test(function (done) {
        const stream = new Stream.Readable()
        stream.push('data')
        stream.push(null)

        const client = new RedisMock()
        this.stub(client, 'exists').yields(null, 1)

        const getRange = this.stub(client, 'getrange')
        getRange
          .withArgs(Buffer.from('key1'), 0, 16383)
          .yields(null, Buffer.from('data'))
        getRange
          .withArgs(Buffer.from('key1'), 16384, 32767)
          .yields(null, Buffer.from(''))

        this.stub(noderedis, 'createClient').returns(client)

        cache = new Cache({
          directory: { enabled: false, path: './cache', extension: 'json' },
          redis: { enabled: true, host: '127.0.0.1', port: 6379 }
        })

ioredis-mock

This library emulates ioredis by performing all operations in-memory.

MIT
Latest version published 1 year ago

Package Health Score

71 / 100
Full package analysis