node-redis: URL not working.

Issue

import { RedisClient } from 'redis'
new RedisClient({
      url: "redis://rediscloud:pass@redis-ttt.ttt.eu-central-1-1.ec2.cloud.redislabs.com:13180"
});

Why is this not working? It’s giving me this error: Error: Redis connection to 127.0.0.1:6379 failed


Environment

  • Node.js Version: v12.14.1
  • Redis Version: 4.0.9
  • Platform: Windows 10 & Ubuntu

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 7
  • Comments: 19 (1 by maintainers)

Most upvoted comments

I connected mine like this:

import { createClient } from “redis”;

const redis = createClient({ url: redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}, });

@supertiger1234 instead of new RedisClient you should use redis.createClient

createClient() takes in an options object as a parameter, you should set the URL there. For more info look at the type definition found under client.d.ts. -> RedisClientOptions

import { createClient } from 'redis'

const client = createClient({ url: process.env.REDIS_URL })

Still broken, have been stuck on this for 8 hours now. I thought that docker’s bridge is assigning wrong aliases, but the issue was here 😞

This works for me :

import { createClient } from "redis";
const { Url } = require("url");


const url = `redis://${REDIS_DATABASE_HOST}:${REDIS_DATABASE_PORT}`;
const redisClient = createClient({
  url: Url(url),
  password: REDIS_PASSWORD,
});

Still not working

Working solution for typescript:

import { createClient, RedisClient } from 'redis';

const client: RedisClient = createClient(redisUrl);