stipsan / ioredis-mock

Emulates ioredis by performing all operations in-memory.
MIT License
341 stars 124 forks source link

client() function is missing #1060

Open moyarich opened 3 years ago

moyarich commented 3 years ago

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();
stipsan commented 3 years ago

Hey, could you make a repro on RunKit?

moyarich commented 3 years ago

Here is the repo on runkit

https://runkit.com/embed/ph0wmm5wsao2

stipsan commented 3 years ago

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 🙂

moyarich commented 3 years ago

@stipsan thank you