Zum Inhalt springen

CRUD data with Upstash with NoSQL operations

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Make sure to update the .env file or hosting provider’s environment variable to have the necessary variables for Upstash:

Terminal window
# Obtain the Upstash API keys
# After following the https://upstash.com/docs/redis/overall/getstarted
UPSTASH_REDIS_REST_URL="..."
UPSTASH_REDIS_REST_TOKEN="..."
// File: random.ts OR random.astro
import redis from '@/lib/db/upstash'
// Use redis commands
// For example
// To set into hash set
await redis.hget('key1', 'key2', 'value1')
// To get from hash set
await redis.hget('key1', 'key2')
// To get from collection
await redis.get('key3')
// To set in collection
await redis.set('key3', 'value2')