ioredis-mock
ioredis-mock copied to clipboard
client() function is missing
I was trying to use iosredis-mock with the bull queue library when it screamed at me saying that "client is not a function" It looks like iosredis has a client function.
this is the code that I was trying to make work
/**
* https://github.com/OptimalBits/bull
*
*/
async function mockBullQ(){
const Queue = require("bull");
const RedisMock = require('ioredis-mock');
//------------------------
const redisMock = new RedisMock();
redisMock.set('hello', '--->Testing: redis mock is working');
console.log(await redisMock.get('hello'));
//------------------------
/**
* *
* I have no idea what client does, not sure what to return for this function
* https://github.com/OptimalBits/bull/blob/088e5dfcbe9b5c347c2c8f5d9fca5c53c099bbe3/lib/worker.js
*
* Sample data passed to function:
* key: "setname"
* value: "bull:bW9ja2VkU"
*/
/*
RedisMock.prototype.client = function(key,value){
this.set([key], value);
this.status = 'ready';
console.log(`--> client() function called with --> key: "${key}" value: "${value}"`);
return this;
}
*/
function createClient(){
return new RedisMock();
}
const queue = new Queue("mockedQueue",{createClient});
//Producer
queue.add({ "name": "Moya Rich" });
//Worker
queue.process(async (job) => {
console.log("\n\n---job--->>>>>>>", job);
});
}
mockBullQ();
Hey, could you make a repro on RunKit?
Here is the repo on runkit
https://runkit.com/embed/ph0wmm5wsao2
Thanks @moyarich! I see now that the error comes from bull queue trying to call CLIENT SETNAME, while we don't support the CLIENT suite of redis commands yet. PRs welcome 😄 Meanwhile I'll make a PR that makes these errors more useful 🙂
@stipsan thank you