New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streaming server response #1179
Comments
👍 it would be great if we have implementation for it |
@aletorrado I already had similar situation and I wanted to stream from HKEYS cmd const redis = require('redis');
const connectionParams = {};
class HKeysReadable extends require('stream').Readable {
constructor(key, chunkSize, opt) {
opt = opt || {};
opt.objectMode = true;
super(opt);
this._cursor = 0;
this.key = key;
this.chunkSize = chunkSize;
this.client = redis.createClient(connectionParams);
}
_read() {
if (this._cursor === '0') {
this.push(null);
return this.client.quit();
}
this.client.hscan(this.key, this._cursor, 'COUNT', this.chunkSize, (err, res) => {
if (err) {
this.push(null);
this.client.quit();
return process.nextTick(() => this.emit('error', err));
}
this._cursor = res[0];
/**
*
SCAN returns value as an array of two values, the first value is the new cursor to use in the next call,
the second value is an array of elements like: [key1, val1, key2, val2, key3, val3, .....]
In this stream, we need the keys only so we reduce that array to get only the odd values which contain the keys
*/
let keys = res[1].reduce((accumulator, val, index)=> {
if (!(index % 2)) {
accumulator.push(val);
}
return accumulator;
}, []);
if (keys.length > 0) {
this.push(keys);
}
}
);
}
}; @BridgeAR what do you think? is there a possibility to adapt similar implementation in Redis library as well? |
Great @hossam-fares. Basically it may abstract cursors from |
@hossam-fares I would definitely like to have something similar implemented 👍 |
@BridgeAR cool, I will work on a PR for it |
Has this been implemented? |
@aletorrado @hossam-fares @revington I think that for await (const key of client.scanIterator()) {
console.log(key);
} what do you think? |
Hi, is possible with
node_redis
to stream the server response with commands likeHMGET
orKEYS
?Thanks.
The text was updated successfully, but these errors were encountered: