rsmq
rsmq copied to clipboard
Add ioRedis support
Hi @smrchy,
This commit is a minimally invasive first-pass attempt at adding ioRedis support.
The main difference between ioredis and node-redis that affects rsmq is the difference in the return result from the multi
function. This patch works around that by translating the ioredis response format to the node-redis format. It passes all the same node-redis test cases when using ioRedis, and is working with the application I'm developing.
Please let me know what you think about this approach. I'd like to get this (or some similar patch that adds ioredis support) upstreamed if at all possible.
Woah, this has been totally abandoned, a shame, really :(
Hello, can we merge it to latest version? It's very usefull
We moved to bull
, it's almost as simple and easy to work with it as with rsmq.
A workaround using Proxy
new RSMQ({
client: new Proxy(ioredisClient, {
get(target, key, receiver) {
if (key === 'constructor') {
return { name: 'RedisClient' };
}
if (key === 'connected') {
return target.status === 'ready';
}
if (key === 'multi') {
// Note that `multi` proxy is minimal wrapping for RSMQ.
return new Proxy(target[key], {
apply(target, thisArg, argArray) {
return new Proxy(target.apply(thisArg, argArray), {
get(target2, key2, receiver2) {
if (key2 === 'exec') {
return (cb) => {
target2.exec((err, res) => {
cb(
err,
res
? res.map(([err, val]) => {
if (err) {
throw err;
}
return val;
})
: res
);
});
};
} else {
return target2[key2];
}
}
});
}
});
} else {
return target[key];
}
}
})
})
A workaround using
Proxy
new RSMQ({ client: new Proxy(ioredisClient, { get(target, key, receiver) { if (key === 'constructor') { return { name: 'RedisClient' }; } if (key === 'connected') { return target.status === 'ready'; } if (key === 'multi') { // Note that `multi` proxy is minimal wrapping for RSMQ. return new Proxy(target[key], { apply(target, thisArg, argArray) { return new Proxy(target.apply(thisArg, argArray), { get(target2, key2, receiver2) { if (key2 === 'exec') { return (cb) => { target2.exec((err, res) => { cb( err, res ? res.map(([err, val]) => { if (err) { throw err; } return val; }) : res ); }); }; } else { return target2[key2]; } } }); } }); } else { return target[key]; } } }) })
Hi rokoroku, could you please explain where we can find the "proxy" library, you are using in your code snippet?
@edima77 Proxy is Part of ECMAScript 2015 and according to MDN it is supported sinde node 6.x.
Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
I've updated this PR to the current version of RSMQ. It passes all the same tests with both ioredis
or redis
.
Hmm, is there still no support for ioredis in rsmq?