Closed elie222 closed 8 months ago
Not doing this. The above method should work
Another option is to support it in the code like so:
import { env } from "@/env.mjs";
// Function to dynamically import Redis based on user preference or environment variable
async function getRedisClient() {
let RedisClient;
if (env.UPSTASH_REDIS_URL) {
const { Redis } = await import("@upstash/redis");
RedisClient = new Redis({
url: env.UPSTASH_REDIS_URL,
token: env.UPSTASH_REDIS_TOKEN,
});
} else {
const { createClient } = await import("redis");
RedisClient = createClient({ url: env.REDIS_URL });
await RedisClient.connect();
}
return RedisClient;
}
export const redis = await getRedisClient();
And change target
to ES2017
in packages/tsconfig/nextjs.json
.
Also needs some TS work to make it compatible. Here's a POC: https://github.com/elie222/inbox-zero/tree/redis-without-upstash
But I think I prefer the Docker option for now so we don't need to install two different packages.
Hi @elie222 I would love to solve this issue could you please assign me.
Hi @elie222 I would love to solve this issue could you please assign me.
Done!
It may be very simple and just copy pasting a few lines into the Docker Compose. Just need to check that it actually works. I don't want to mess around with changing our code (the 2nd option I put above), as it will be more long term maintenance.
A solution is to update the Docker Compose to this: https://github.com/hiett/serverless-redis-http#via-docker-compose
Then you don't need to use Upstash Redis.