Skip to content

Commit

Permalink
Merge pull request #72 from upstash/hotfix-redis-env-vars
Browse files Browse the repository at this point in the history
Use fromEnv or KV env vars in redis templates
  • Loading branch information
CahidArda authored Oct 21, 2024
2 parents c0cbe16 + a06e066 commit de9a368
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
5 changes: 1 addition & 4 deletions examples/nextjs-with-redis/src/app/api/increment/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { Redis } from '@upstash/redis';
import { NextResponse } from 'next/server';

// Initialize Redis
const redis = new Redis({
url: process.env.UPSTASH_REDIS_REST_URL || '',
token: process.env.UPSTASH_REDIS_REST_TOKEN || '',
});
const redis = Redis.fromEnv()

export const GET = async () => {
const identifier = 'api_call_counter';
Expand Down
5 changes: 1 addition & 4 deletions examples/nuxt-with-redis/server/api/increment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { defineEventHandler } from "h3";
import { Redis } from "@upstash/redis";

// Initialize Redis
const redis = new Redis({
url: process.env.UPSTASH_REDIS_REST_URL || "",
token: process.env.UPSTASH_REDIS_REST_TOKEN || ""
});
const redis = Redis.fromEnv()

export default defineEventHandler(async () => {
const identifier = "api_call_counter";
Expand Down
10 changes: 9 additions & 1 deletion examples/sveltekit-with-redis/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# You must configure one of the following sets:
# - Both UPSTASH_REDIS_REST_URL & UPSTASH_REDIS_REST_TOKEN
# or
# - Both KV_REST_API_URL & KV_REST_API_TOKEN

UPSTASH_REDIS_REST_URL=""
UPSTASH_REDIS_REST_TOKEN=""
UPSTASH_REDIS_REST_TOKEN=""

KV_REST_API_URL=""
KV_REST_API_TOKEN=""
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { UPSTASH_REDIS_REST_TOKEN, UPSTASH_REDIS_REST_URL } from "$env/static/private";
import * as env from "$env/static/private";
import { json } from '@sveltejs/kit';
import { Redis } from '@upstash/redis';

// Initialize Redis
const redis = new Redis({
url: UPSTASH_REDIS_REST_URL || "",
token: UPSTASH_REDIS_REST_TOKEN || ""
url: env.UPSTASH_REDIS_REST_URL || env.KV_REST_API_URL || "",
token: env.UPSTASH_REDIS_REST_TOKEN || env.KV_REST_API_TOKEN || ""
});

export async function GET() {
Expand Down

0 comments on commit de9a368

Please sign in to comment.