rsmq icon indicating copy to clipboard operation
rsmq copied to clipboard

Add ioRedis support

Open itaylor opened this issue 7 years ago • 8 comments

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.

itaylor avatar Aug 31 '17 07:08 itaylor

Woah, this has been totally abandoned, a shame, really :(

petekanev avatar Dec 17 '18 11:12 petekanev

Hello, can we merge it to latest version? It's very usefull

ghost avatar Jan 15 '19 13:01 ghost

We moved to bull, it's almost as simple and easy to work with it as with rsmq.

petekanev avatar Jan 15 '19 15:01 petekanev

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];
      }
    }
  })
})

rokoroku avatar Aug 22 '19 02:08 rokoroku

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 avatar Aug 26 '19 09:08 edima77

@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

erdii avatar Aug 26 '19 11:08 erdii

I've updated this PR to the current version of RSMQ. It passes all the same tests with both ioredis or redis.

itaylor avatar Dec 06 '19 06:12 itaylor

Hmm, is there still no support for ioredis in rsmq?

kinseyost avatar Aug 23 '23 22:08 kinseyost