elie222 / inbox-zero

Open source email app to reach inbox zero fast.
https://getinboxzero.com
GNU Affero General Public License v3.0
2.53k stars 258 forks source link

Allow using regular Redis #89

Closed elie222 closed 8 months ago

elie222 commented 8 months ago

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.

elie222 commented 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.

asif-reh commented 8 months ago

Hi @elie222 I would love to solve this issue could you please assign me.

elie222 commented 8 months ago

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.