Skip to content

Use fromEnv or KV env vars in redis templates #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading