Ioredis: scanStream in cluster mode?

Created on 14 Oct 2015  路  8Comments  路  Source: luin/ioredis

it seems that scanStream() is not available when using ioredis.Cluster(), although scan() is.
Any particular reason for this, or is this a requestable feature? ;-)

Most helpful comment

    let nodes = redis.nodes('master'),
        scanNode = (nodeIndex) => {
            let node = nodes[nodeIndex];
            node.scanStream({
                count: 10000
            }).on('data', rs => {
                rs.forEach(r => console.debug("key", r));
            }).on('end', () => {
                console.info("scan end, node %s:%d", node.options.host, node.options.port);
                if (++nodeIndex < nodes.length) {
                    scanNode(nodeIndex);
                } else {
                    console.info("scan finished");
                    redis.quit();
                }
            });
            console.info("scan start, node %s:%d", node.options.host, node.options.port);
        };
    scanNode(0);

Iterate over all Cluster Master Nodes, and then scan every single Node

All 8 comments

Commands that doesn't have a key name as the arguments(e.g. scan, keys & info) will be sent to a random node of the cluster. So that it doesn't make sense to provide scanStream in the cluster mode since it will only scan a random node instead of the whole cluster.

Ah, thanks for clearing that up.

Is that also the case for the other scan commands like hscan?
I mean, they do have a key as an argument. Couldn't that work? And please excuse my ignorance about cluster internals.

Yes, you're right. Other scan commands work with cluster. I'll consider whether to implement it.
Any pr is welcome :-)

Released in v1.11.0 :rocket:

tested with ioredis 3.1.4 and scanStream function is missing from Redis.Cluster

+1 on this. There is still no scanStream function in Redis.Cluster. However you can use cluster.subscriber.scanStream to scan on currently connected slot.

    let nodes = redis.nodes('master'),
        scanNode = (nodeIndex) => {
            let node = nodes[nodeIndex];
            node.scanStream({
                count: 10000
            }).on('data', rs => {
                rs.forEach(r => console.debug("key", r));
            }).on('end', () => {
                console.info("scan end, node %s:%d", node.options.host, node.options.port);
                if (++nodeIndex < nodes.length) {
                    scanNode(nodeIndex);
                } else {
                    console.info("scan finished");
                    redis.quit();
                }
            });
            console.info("scan start, node %s:%d", node.options.host, node.options.port);
        };
    scanNode(0);

Iterate over all Cluster Master Nodes, and then scan every single Node

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lakano picture lakano  路  3Comments

saschaishikawa picture saschaishikawa  路  4Comments

pavanratnakar picture pavanratnakar  路  4Comments

pensierinmusica picture pensierinmusica  路  5Comments

ORESoftware picture ORESoftware  路  5Comments