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 setawait redis.hget('key1', 'key2', 'value1')
// To get from hash setawait redis.hget('key1', 'key2')
// To get from collectionawait redis.get('key3')
// To set in collectionawait redis.set('key3', 'value2')
// File: +page.server.ts OR +server.ts
import redis from '@/lib/db/upstash'
// Use redis commands// For example
// To set into hash setawait redis.hget('key1', 'key2', 'value1')
// To get from hash setawait redis.hget('key1', 'key2')
// To get from collectionawait redis.get('key3')
// To set in collectionawait redis.set('key3', 'value2')