ioredis-mock icon indicating copy to clipboard operation
ioredis-mock copied to clipboard

redis.scanStream not working correctly

Open khawkinson opened this issue 5 years ago • 3 comments

created a repo duplicating the problem: https://github.com/khawkinson/ioredis-mock-test

Basically this fails:

import RedisMock from 'ioredis-mock';
import { describe, it } from 'mocha';
import { expect } from 'chai';

describe('ioredis-mock test', () => {
  let redis;
  beforeEach(() => {
    redis = new RedisMock({
      data: {
        'user:1': 'bill',
        'user:2': 'steve',
        'user:3': 'john',
        'user:4': 'billy',
        'user:5': 'erin',
        'user:6': 'paul',
        'user:7': 'jim',
        'user:8': 'dave',
        'user:9': 'peter',
        'user:10': 'james',
        'user:11': 'don',
        'user:13': 'aaron',
        'user:14': 'bill',
        'user:15': 'steve',
        'user:16': 'john',
        'user:17': 'billy',
        'user:18': 'erin',
        'user:19': 'paul',
        'user:20': 'jim',
        'user:21': 'dave',
        'user:22': 'peter',
        'user:23': 'james',
        'user:24': 'don',
        'user:25': 'aaron',
        'user:25:balls': new Set(['balls'])
      }
    });
  });
  describe('', () => {
    it('should properly do a scan', () => {
      const finalTally = [];
      // ADD count to options object, { match: 'user:*', count: 100 }
      // Test will pass.
      // if you use a count value less than what should be returned, it also fails.
      // like count: 10
      const stream = redis.scanStream({ match: 'user:*' });
      stream.on('data', keys => {
        if (keys.length) {
          console.log(keys);
          const pipeline = redis.pipeline();
          keys.forEach((key) => {
            finalTally.push(key);
            pipeline.del(key);
          });
          pipeline.exec();
        }
      });

      stream.on('end', () => {
        expect(finalTally.length).to.equal(25);
      })
    });
  });
});

khawkinson avatar Sep 13 '19 20:09 khawkinson

Issue still occuring :(

Shahor avatar Dec 11 '20 14:12 Shahor

Issue still occuring :(

PRs welcome 😉

stipsan avatar Dec 11 '20 16:12 stipsan

+1

ThallyssonKlein avatar Jan 06 '22 10:01 ThallyssonKlein