Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ioRedis support #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add ioRedis support #57

wants to merge 2 commits into from

Conversation

itaylor
Copy link

@itaylor itaylor commented Aug 31, 2017

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.

@petekanev
Copy link

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

@erdii erdii requested a review from smrchy December 17, 2018 15:16
@ghost
Copy link

ghost commented Jan 15, 2019

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

@petekanev
Copy link

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

@rokoroku
Copy link

rokoroku commented Aug 22, 2019

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

@edima77
Copy link

edima77 commented Aug 26, 2019

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?

@erdii
Copy link
Contributor

erdii commented Aug 26, 2019

@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

@itaylor
Copy link
Author

itaylor commented Dec 6, 2019

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

@kinseyost
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants