upstash
npx skills add https://upstash.com
Agent 安装分布
Skill 文档
Capabilities
Upstash provides a comprehensive serverless data platform with five core products:
- Serverless Redis: High-performance, globally replicated Redis-compatible database with REST API access
- Vector Database: Specialized database for semantic search and similarity matching with embedding support
- QStash: Serverless message queue and scheduling service for reliable background jobs and event processing
- Workflow: Durable orchestration layer for multi-step serverless functions with automatic retries and state management
- Realtime: Low-latency messaging for real-time applications with channel-based pub/sub
- Search: Full-text and semantic search database for building search experiences
All services scale to zero, charge per-request, support global replication, and are accessible via REST APIs from any runtime.
Skills
Redis Database
Core Operations
- Create and manage Redis databases with multi-region replication
- Execute all standard Redis commands (strings, hashes, lists, sets, sorted sets, streams, JSON)
- Use REST API for HTTP-based access:
GET /get/key,POST /set/keywith Bearer token authentication - Support for pipelining multiple commands in single HTTP request
- Atomic transactions via
/multi-execendpoint - Pub/Sub messaging with
SUBSCRIBE,PUBLISH, and pattern matching
Data Structures
- String operations: SET, GET, INCR, APPEND, GETRANGE
- Hash operations: HSET, HGET, HGETALL, HINCRBY, HSCAN
- List operations: LPUSH, RPUSH, LPOP, LRANGE, LINSERT
- Set operations: SADD, SMEMBERS, SINTER, SUNION, SDIFF
- Sorted Set operations: ZADD, ZRANGE, ZRANK, ZINCRBY, ZINTERSTORE
- Stream operations: XADD, XREAD, XGROUP, XACK for event streaming
- JSON operations: JSON.SET, JSON.GET, JSON.ARRAPPEND for structured data
Advanced Features
- Automatic backups and point-in-time recovery
- Key expiration with TTL management (EXPIRE, PEXPIRE, TTL)
- Keyspace notifications for event-driven architectures
- Lua scripting with EVAL and EVALSHA
- Bitmap operations for efficient flag storage
- HyperLogLog for cardinality estimation
Rate Limiting SDK
Rate Limiting Algorithms
- Fixed window rate limiting: Allow N requests per time window
- Sliding window rate limiting: Smooth request distribution
- Token bucket algorithm: Flexible rate control with burst capacity
- Custom token consumption: Different rates for different request types
Traffic Protection
- Deny lists blocking by IP address, user agent, country, or custom identifier
- Multi-region rate limiting across distributed Redis instances
- Analytics dashboard tracking request patterns and blocked requests
- Dynamic rate limit adjustment at runtime without recreating instances
Configuration
- Per-user, per-API-key, or per-IP rate limiting
- Different limits for free vs. paid tiers
- Timeout handling with default allow behavior
- Local caching to reduce Redis calls
Vector Database
Vector Operations
- Upsert vectors with metadata:
index.upsert({id, vector, metadata}) - Similarity search:
index.query({vector, topK, includeMetadata}) - Metadata filtering with complex queries
- Resumable queries for large result sets
- Fetch vectors by ID:
index.fetch(id) - Range queries:
index.range(startId, endId) - Delete vectors:
index.delete(id) - Update vector metadata
Index Types
- Dense indexes for semantic/embedding search
- Sparse indexes for keyword/full-text search
- Hybrid indexes combining dense and sparse
- Configurable dimensions and distance metrics (Euclidean, Cosine, DotProduct)
- Namespace support for multi-tenancy
Features
- Automatic embedding generation with built-in models
- Metadata-based filtering on search results
- Batch operations for efficient bulk indexing
- Eventually consistent reads with configurable freshness
- Resumable queries for handling large datasets
QStash Message Queue
Message Publishing
- Publish messages to HTTP endpoints:
client.publishJSON({url, body}) - Guaranteed delivery with automatic retries
- Message deduplication to prevent duplicates
- Batch publishing for multiple messages
- Custom headers and authentication support
Scheduling
- Cron-based scheduling:
client.schedules.create({destination, cron}) - Timezone support with IANA timezone identifiers
- One-time delayed delivery:
client.publishJSON({url, body, delay}) - Schedule management: create, update, delete, list schedules
Advanced Features
- URL Groups for fan-out to multiple endpoints
- Queues with FIFO ordering for sequential processing
- Flow control with rate limiting (requests per second, parallelism)
- Dead Letter Queue (DLQ) for failed messages
- Callbacks to notify when messages are delivered
- Batch operations for efficient bulk processing
Message Configuration
- Custom retry policies with exponential backoff
- Message timeout configuration
- Request body size up to 1MB (customizable)
- HTTP method specification (POST, PUT, PATCH)
- Custom headers and authentication tokens
Workflow Orchestration
Workflow Definition
- Multi-step serverless functions with automatic state management
- Step-based execution with individual retry logic
- Durable state preservation across function invocations
- Built on QStash for reliability and scalability
Core Operations
context.run(): Execute a function step with automatic retrycontext.sleep(): Pause workflow for specified durationcontext.sleepUntil(): Sleep until specific timestampcontext.call(): Call external HTTP endpoints with retrycontext.invoke(): Call other workflowscontext.waitForEvent(): Wait for external eventscontext.createWebhook(): Generate webhook URLs for callbackscontext.notify(): Send notifications to waiting steps
Advanced Features
- Parallel step execution with
Promise.all() - Flow control with rate limiting and parallelism limits
- Failure callbacks for error handling
- Dead Letter Queue for failed workflows
- Event-driven workflows with wait/notify patterns
- Long-running task support beyond serverless timeouts
- Scheduled workflows with cron expressions
Client Operations
client.trigger(): Start workflow executionclient.cancel(): Cancel running workflowclient.logs(): Retrieve workflow execution logsclient.notify(): Send events to waiting workflows- DLQ management: list, restart, resume, delete failed runs
Search Database
Search Operations
- Full-text search:
index.search({query, limit}) - Semantic search with embeddings
- Metadata-based filtering on search results
- Reranking for improved relevance
- Fetch documents by ID:
index.fetch(id) - Range queries:
index.range(startId, endId) - Delete documents:
index.delete(id) - Batch upsert documents
Document Management
- Upsert documents with content and metadata
- Index-based organization for multi-tenancy
- Content and metadata separation
- Automatic indexing on document creation
- Document deletion and updates
Features
- Advanced reranking algorithms
- Configurable search result limits
- Metadata filtering with complex queries
- Multiple indexes per database
- Data browser UI for testing
Realtime Messaging
Channel Operations
- User-specific channels:
realtime.channel('user-{userId}') - Room-based channels:
realtime.channel('room-{roomId}') - Team/workspace channels:
realtime.channel('team-{teamId}') - Emit events:
channel.emit('event.name', data) - Subscribe to channels with event filtering
Features
- Server-side and client-side usage
- Message history retrieval
- Middleware support for authentication
- Serverless-friendly architecture
- Low-latency delivery
Workflows
Building a Rate-Limited API
- Create Redis database in Upstash console
- Initialize Ratelimit SDK with Redis connection
- Configure rate limiting algorithm (fixed/sliding window)
- In request handler, call
ratelimit.limit(identifier, options) - Check
successflag to allow/deny request - Optionally enable traffic protection with deny lists
- Monitor analytics dashboard for patterns
Processing Background Jobs with QStash
- Create public HTTP endpoint for job logic
- From client/server, call
qstash.publishJSON({url, body}) - QStash delivers message to endpoint with automatic retries
- Endpoint processes message and returns 200 status
- Failed messages go to Dead Letter Queue
- Use DLQ to inspect and retry failed jobs
- Monitor logs in Upstash console
Scheduling Recurring Tasks
- Create QStash schedule with cron expression
- Specify destination URL and timezone
- QStash publishes message on schedule
- Endpoint receives and processes message
- Update schedule by creating with same schedule ID
- Delete schedule when no longer needed
- View schedule history in console
Building Semantic Search
- Create Vector index with dense type
- Generate embeddings for documents (via API or SDK)
- Upsert vectors with metadata:
index.upsert({id, vector, metadata}) - Query with embedding:
index.query({vector, topK: 10}) - Filter results by metadata
- Fetch full documents by ID
- Update vectors as content changes
Orchestrating Multi-Step Workflows
- Define workflow endpoint with
serve(async (context) => {}) - Break logic into steps using
context.run() - Use
context.sleep()for delays - Call external APIs with
context.call() - Wait for events with
context.waitForEvent() - Handle failures with failure callbacks
- Trigger workflow with
client.trigger() - Monitor execution with
client.logs()
Building Real-Time Applications
- Create Realtime instance with credentials
- Define channels for users/rooms/teams
- Server emits events:
channel.emit('event', data) - Client subscribes:
useRealtime({channels, events}) - Client receives events in real-time
- Optionally retrieve message history
- Use middleware for authentication
Integration
Framework Support
- Next.js (App Router and Pages Router)
- Vercel Functions and Vercel deployments
- Cloudflare Workers and Durable Objects
- AWS Lambda and AWS SAM
- Google Cloud Functions
- Azure Functions
- Deno Deploy
- Fly.io
- FastAPI, Flask, Django (Python)
- Express.js, Hono, Astro
- Laravel, Supabase
SDK Languages
- TypeScript/JavaScript:
@upstash/redis,@upstash/qstash,@upstash/vector,@upstash/workflow - Python:
upstash-redis,upstash-qstash,upstash-vector - Go: Official Go SDKs
- PHP: Official PHP SDKs
Third-Party Integrations
- LangChain for AI/ML workflows
- LlamaIndex for document indexing
- OpenAI and Anthropic for LLM integration
- Datadog and Prometheus for monitoring
- Resend for email delivery
- n8n and Pipedream for automation
- BullMQ for job queues
- Sidekiq for Ruby background jobs
- Celery for Python task queues
- Drizzle ORM for database operations
- MCP (Model Context Protocol) for AI tools
Developer Tools
- Terraform provider for infrastructure as code
- Pulumi for programmatic infrastructure
- CLI for local development
- Developer API for account management
- REST API for all services
Context
Serverless Architecture
- Per-request pricing model: Pay only for what you use
- Scale to zero: No charges when idle
- No connection management required
- Ideal for AWS Lambda, Vercel, Cloudflare Workers
- HTTP-based access from any runtime
Global Replication
- Multi-region data replication for low latency
- Read replicas in different regions
- Automatic failover for high availability
- 99.99% uptime SLA (Prod Pack)
Data Consistency
- Redis: Strong consistency with optional replication
- Vector: Eventually consistent with configurable freshness
- Transactions support for atomic operations
- Pub/Sub for event-driven architectures
Security
- Bearer token authentication
- Read-only tokens for public access
- ACL support for fine-grained permissions
- TLS encryption in transit
- Optional encryption at rest
- SOC-2 compliance available
Performance Characteristics
- Ultra-low latency worldwide
- Automatic scaling without configuration
- Pipelining support for batch operations
- Connection pooling handled automatically
- REST API eliminates TCP connection overhead
Limitations and Considerations
- Redis: Supports protocol up to version 8.2
- Blocking commands (BLPOP, BRPOP) not supported in REST API
- Vector: Eventually consistent reads
- QStash: 1MB message size limit (customizable)
- Workflow: Built on QStash, inherits its limitations
- Realtime: Serverless-optimized, not for persistent connections
For additional documentation and navigation, see: https://upstash.com/docs/llms.txt