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

non-static ReplyTransformer? #895

Closed
Jonahss opened this issue Jun 13, 2019 · 2 comments
Closed

non-static ReplyTransformer? #895

Jonahss opened this issue Jun 13, 2019 · 2 comments

Comments

@Jonahss
Copy link

Jonahss commented Jun 13, 2019

Hi,

I'm the author of ioredisgraph, which just wraps ioredis, adds a new parameter to the constructor, and sets a custom ReplyTransformer.

Is there a way to set different ReplyTransformers for different instances of the client? The way that redisgraph works, my ReplyTransformer needs to behave differently depending on which db is being accessed.

Jonahss added a commit to Jonahss/ioredisgraph that referenced this issue Jun 13, 2019
…Transformers are static. and i need them bound to individual instances. filed redis/ioredis#895
@luin
Copy link
Collaborator

luin commented Jun 13, 2019

One possible way is to override the instance method directly:

const asCallback = require('standard-as-callback').default
const Redis = require('ioredis')

const redis = new Redis()
const { mset } = redis
redis.mset = function (...args) {
  const callback = typeof args[args.length - 1] === 'function' ? args.pop() : null
  return asCallback(mset(...args).then(transformer), callback)
}

Haven't tested the code though. 🤣

@Jonahss
Copy link
Author

Jonahss commented Jun 14, 2019

Oh okay, that should work fine. I'll just override the redis.call method.

Thanks!

@Jonahss Jonahss closed this as completed Jun 14, 2019
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

No branches or pull requests

2 participants