All skills
upstash avatar

/upstash-redis-js

@35da719
by upstashupstash/skills27 stars
7

Work with the @upstash/redis TypeScript/JavaScript SDK, a serverless HTTP-based Redis client for Next.js, Vercel, Cloudflare Workers, edge runtimes, and Node.js. Use when adding a cache (cache-aside, write-through, TTL and expiration strategies), session storage and user sessions, a key-value store, leaderboards and rankings with sorted sets, counters, distributed locks, queues with lists, streams and consumer groups, sparse index-addressed arrays and ring buffers (ARSET, ARINSERT, ARRING, ARGREP, AROP), embeddings and nearest-neighbour vector search stored inside Redis (VECTOR commands via redis.vector, separate from @upstash/vector), JSON documents, pipelines and MULTI/EXEC transactions, Lua scripting, read replicas, or full-text search, typo-tolerant search, facets, aggregations, and search over Redis stream entries with Upstash Redis Search (different from regular FT.SEARCH; also available for TCP clients via @upstash/search-redis and @upstash/search-ioredis). Also use when migrating from ioredis or node-redis, when a Redis connection is needed from a serverless function without connection pooling, when integrating @upstash/ratelimit, or when the user says Redis cache, KV store, session store, serverless Redis, or Upstash Redis. Supports automatic serialization/deserialization of JavaScript types.

Use this Skill: https://skilld.dev/gh/upstash/skills/upstash-redis-js

This session only. Nothing lands on disk.

performancepipeline-optimization.md

≈609 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Pipeline Optimization

Overview

Pipelines batch multiple Redis commands into one HTTP request. Use automatic pipelines for Promise.all patterns, manual pipelines for sequential operations.

Good For

  • Multiple independent operations
  • High-latency networks
  • Serverless functions with cold starts
  • Operations that don't depend on each other's results

Limitations

  • Commands in pipeline cannot depend on previous results
  • Large pipelines increase memory usage
  • Errors in one command don't stop others

Examples

Auto-Pipeline Basics

import { Redis } from "@upstash/redis";

// Auto-pipeline: enable globally
const redis = new Redis({
  url: process.env.UPSTASH_REDIS_REST_URL!,
  token: process.env.UPSTASH_REDIS_REST_TOKEN!,
  enableAutoPipelining: true,
});

// With auto-pipeline: Promise.all batches automatically
const [user, posts, comments] = await Promise.all([
  redis.get("user:1"),
  redis.lrange("posts:1", 0, 9),
  redis.lrange("comments:1", 0, 9),
]);
// Single HTTP request!

Manual Pipeline

import { Redis } from "@upstash/redis";

const redis = Redis.fromEnv();

// Manual pipeline: explicit control
const pipeline = redis.pipeline();
pipeline.get("user:1");
pipeline.lrange("posts:1", 0, 9);
pipeline.lrange("comments:1", 0, 9);

const results = await pipeline.exec();

When to Use Pipelines

import { Redis } from "@upstash/redis";

const redis = Redis.fromEnv();

// ❌ Bad: second operation depends on first
const bad = redis.pipeline();
bad.get("counter");
bad.incr("counter"); // Might not see previous get result
await bad.exec();

// ✅ Good: independent operations
const good = redis.pipeline();
good.get("user:1");
good.get("user:2");
good.get("user:3");
await good.exec();

Pipeline Size Optimization

import { Redis } from "@upstash/redis";

const redis = Redis.fromEnv();
const OPTIMAL_SIZE = 50;

async function pipelinedBatch(keys: string[]) {
  const results = [];
  for (let i = 0; i < keys.length; i += OPTIMAL_SIZE) {
    const batch = keys.slice(i, i + OPTIMAL_SIZE);
    const pipeline = redis.pipeline();
    batch.forEach((key) => pipeline.get(key));

    const batchResults = await pipeline.exec();
    results.push(...batchResults);
  }

  return results;
}

// Usage
const keys = Array.from({ length: 200 }, (_, i) => `key:${i}`);
const allResults = await pipelinedBatch(keys);

Source: SKILL.md on GitHub

1 warningtoday3 checks · Risk SAFE
  • Gen Agent Trust Hubtoday

    The skill provides a comprehensive guide for using the Upstash Redis JavaScript SDK. It follows security best practices for credential management by advocating for environment variables and relies on official vendor resources. While the skill facilitates data ingestion from external databases, it does so as a standard database client with no malicious patterns or unexpected behaviors detected.

  • Sockettoday

    1 alert: gptSecurity

  • Snyktoday

    Risk: LOW · No issues

Signed by skilld at 35da719. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated 2 weeks ago
metadata
{
  "author": "Upstash",
  "homepage": "https://upstash.com"
}

README badge

README badge for upstash/skills/upstash-redis-js