Skip to content

no status property and end event #1095

Open
@ulisesbocchio

Description

First off thank you for the good work on this library. Found a couple missing features:
ioredis has a status property to check the connection status of the client (ready, wait, end)
ioredis emits end on disconnect.

quick fix for anyone looking for this until it's resolved:

class IoRedisMock extends RedisMock {
    constructor(opts) {
        super(opts);
        this.lazyConnnect = opts && opts.lazyConnnect;
    }

    get status() {
        return this.connected ? 'ready' : this.lazyConnnect ? 'wait' : 'end';
    }

    disconnect() {
        process.nextTick(() => this.emit('end'));
        super.disconnect();
        this.connected = false;
    }
}
IoRedisMock.Cluster = class IoRedisClusterMock extends IoRedisMock {
    constructor(nodesOptions) {
        super();
        this.nodes = [];
        nodesOptions.forEach(options => this.nodes.push(new IoRedisMock(options)));
    }
};

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions