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

Feature: Direct support for full redis URLs #1039

Closed
hardcodet opened this issue Jan 30, 2022 · 5 comments
Closed

Feature: Direct support for full redis URLs #1039

hardcodet opened this issue Jan 30, 2022 · 5 comments

Comments

@hardcodet
Copy link

hardcodet commented Jan 30, 2022

As discussed, a follow-up task for the question raised here:

Originally posted by @dan003400 in #53 (comment)

Is there any reason connection does not accept just a redis connection string without the need of importing ioredis?
This seems very odd that you can pass in host / port but not only a string with full connection string...

Thanks for your consideration!

@hardcodet hardcodet changed the title Direct support for full redis URLs Feature: Direct support for full redis URLs Jan 30, 2022
@manast
Copy link
Contributor

manast commented Feb 4, 2022

After examining this feature more deeply we have realized that the kind of code changes required do not really motivate the change. In order to keep the API clean, we have decided to not support this feature. Instead, it is recommended to just create the redis instance first and pass it as a parameter:

import * as Redis from 'ioredis';

const connection = new Redis('redis:/qweqeqwe');

const queue = new Queue('test', { connection });

@manast manast closed this as completed Feb 4, 2022
@highri5e
Copy link

highri5e commented Oct 3, 2023

Passing the connection does not work anymore?

"bullmq": "^4.12.0"
"ioredis": "^4.28.3"

Cannot pass the connection to Queue or Worker as shown in the docs.

const conection = new Redis('redis:/qweqeqwe');

const queue = new Queue('test', { connection });

Typescript is complaining about the { connection } object, and building would throw this:

15:39:30 worker.1   |  TypeError: Connection is not a constructor
15:39:30 worker.1   |      at new QueueBase (\node_modules\bullmq\dist\cjs\classes\queue-base.js:41:27)
15:39:30 worker.1   |      at new Worker (\node_modules\bullmq\dist\cjs\classes\worker.js:34:9)

@manast
Copy link
Contributor

manast commented Oct 3, 2023

@highri5e I wonder if that is the correct code considering you misspelled connection (conection)

@highri5e
Copy link

highri5e commented Oct 3, 2023

Sorry. The code was copied from your comment, which had the misspell in it.

This is my code:

import IORedis from 'ioredis';

const connection = new IORedis(_config.REDIS_URL);

export class BullMQueue<T> {
  queue: Queue<T>;

  constructor(queueName: string) {
    this.queue = new Queue<T>(queueName, { connection });
  }

  addJob(name: string, data: T, options?: JobsOptions) {
    return this.queue.add(name, data, options);
  }

  addBulk(jobs: { name: string; data: T; options?: JobsOptions }[]) {
    return this.queue.addBulk(jobs);
  }
}

I tried different options. I have to use the url rather than host, port combo because we're using Heroku and that's what's available.

Locally I was not using the redis connection, I was passing connection options with url. While the connection options object was not correct, everything was working because Bull was using the default redis connection.

@manast
Copy link
Contributor

manast commented Oct 3, 2023

I do not see anything obviously wrong, but here we have some tests that you can use as a starting point to find the issue: https://github.com/taskforcesh/bullmq/blob/master/tests/test_worker.ts#L119

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

3 participants