Skip to content

CRUD data with Upstash with NoSQL operations

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

# 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')