I'm trying to use the redis-om package to connect to a Redis server, but I'm getting the following error: "TypeError: url_1.URL is not a constructor" when using the built-in URL class from Node.js. I have tried using the url.parse() function from the url module instead, but the error persists.
Here is my code with an altered password:
import { Client, Entity, Schema, Repository } from "redis-om";
const client = new Client(); async function connect() { console.log("Will connect to redis"); console.log({ client }); if (!client.isOpen()) {
try {
console.log("Attempting to connect to redis");
const res = await client.open("redis://default:0dOoaiVcvwRsadRdOQVqLDdXmhnRR6HA@redis-15206.c269.eu-west-1-3.ec2.cloud.redislabs.com:15206");
console.log({ res });
} catch (err) {
console.log("Error connecting to redis:");
console.log(err);
} } }
class Post extends Entity {}
let schema = new Schema(Post, { media: { type: "string" }, author: { type: "string" }, caption: { type: "string" }, created: { type: "number" }, });
interface Data { media: string; author: string; caption: string; created: number; }
export async function createPost(data: Data) { await connect();
const repository = client.fetchRepository(schema);
const post = repository.createEntity(data as any);
const id = await repository.save(post);
return id; }
Here is the error client.open() throws:
TypeError: url_1.URL is not a constructor