Emulates ioredis by performing all operations in-memory.
MIT License
Bot releases are hidden (Show)
Published by stipsan over 6 years ago
zscanStream
and hscanStream
commands (#393 @BastienAr)Published by stipsan over 6 years ago
pexpire, pexpireat, psetex
to set correct expire time (#389 @vaskevich)Published by stipsan over 6 years ago
const RedisMock = require('ioredis-mock');
const redis = new RedisMock({
data: {
foo0: 'x',
foo1: 'x',
foo2: 'x',
test0: 'x',
test1: 'x',
},
});
const stream = redis.scanStream({ match: 'foo*' });
// Pipe to whatever stream you want, will return ['foo0', 'foo1', 'foo2']
stream.pipe(process.stdout)
Published by stipsan over 6 years ago
keys
no longer returns empty sets, just like real redis (#358)Published by stipsan over 6 years ago
srandom
not using Set
. (#356 @ianmuninio)Published by stipsan over 6 years ago
Published by stipsan almost 7 years ago
Published by stipsan almost 7 years ago
const data = {
foo: new Map([
['first', { score: 1, value: 'first' }],
['second', { score: 2, value: 'second' }],
['third', { score: 3, value: 'third' }],
['fourth', { score: 4, value: 'fourth' }],
['fifth', { score: 5, value: 'fifth' }],
]),
};
const RedisMock = require('ioredis-mock');
const redis = new RedisMock({ data });
redis
.zrangebyscore('foo', 1, 3)
.then(result => console.log(result)) // logs ['first', 'second', 'third']
In ioredis
this is the equivalent to calling redis.disconnect
. ioredis-mock
does not implement connection simulation functionality yet so for now it's just a stub.
redis.quit() // OK
Our previous release added subscribe
and joining the fray you can now pretend to be unsubscribing (just like the newsletters in your inbox!)
redis.unsubscribe() // OK
Published by stipsan almost 7 years ago
const RedisMock = require('ioredis-mock');
const redis = new RedisMock();
redis.subscribe('news', 'music').then(result => console.log(result)) // logs '2'
Published by stipsan almost 7 years ago
Published by stipsan almost 7 years ago
Published by stipsan almost 7 years ago
Any transformer you use on arguments and replies in ioredis
will work in ioredis-mock
🎉
Since we're now able to load the built in transformers in ioredis
we could finally get rid of old code related to the the hgetall
and hmset
commands.
The following only apply if you use
ioredis-mock
without installingioredis
If this is your use case you'll need to install ioredis
as well or ioredis-mock
will not work as we're using ioredis
internals to stay compatible. Using ioredis-mock
without installing ioredis
have been possible up to now but's newer actually been officially supported. That's why ioredis
have always been specified as a peerDependency
.
Published by stipsan almost 7 years ago
Published by stipsan almost 7 years ago
hmset
This is a stopgap solution until real argument and reply transformers is implemented and fully compatible with ioredis
redis.zadd('myzset', '1', 'one', '1', 'uno', '2', 'two', '3', 'three') // returns `4` as 4 items got added
redis.zrange('myzset', 0, -1) // ['one', 'uno', 'two', 'three']
redis.zrevrange('myzset', 0, -1) // ['three', 'two', 'uno', 'one']
redis.zremrangebyrank('myzset', 0, 2) // returns '3' as that’s how many items got deleted
redis.zrange('myzset', 0, -1) // ['three']
Published by stipsan almost 7 years ago
redis
.scan(0, 'MATCH', 'foo*', 'COUNT', 1)
.then(result => console.log(result))
redis
.lrange('myKey', 0, 2)
.then(result => console.log(result))
Published by stipsan almost 7 years ago
Published by stipsan almost 7 years ago
Published by stipsan about 7 years ago
Published by stipsan about 7 years ago
Added a 'pipeline' method which allows chaining of methods like ioredis.
Updated discard and multi to work with the pipeline.
Published by stipsan about 7 years ago