ioredis-mock icon indicating copy to clipboard operation
ioredis-mock copied to clipboard

client() function is missing

Open moyarich opened this issue 3 years ago • 4 comments

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();

moyarich avatar Mar 31 '21 16:03 moyarich

Hey, could you make a repro on RunKit?

stipsan avatar Apr 15 '21 16:04 stipsan

Here is the repo on runkit

https://runkit.com/embed/ph0wmm5wsao2

moyarich avatar Apr 19 '21 12:04 moyarich

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 avatar Apr 19 '21 13:04 stipsan

@stipsan thank you

moyarich avatar Apr 19 '21 16:04 moyarich