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.

data-structureslists.md

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

Lists

Overview

Lists are ordered collections of strings. They support operations at both ends (head and tail) with O(1) time complexity.

Good For

  • Activity feeds (latest posts, news)
  • Job queues
  • Recent items (last 100 searches)
  • Stack or queue implementations

Limitations

  • Maximum length: 2^32 - 1 (4.2 billion) elements
  • Accessing elements by index is O(N) for large lists
  • No built-in deduplication (use sets for unique values)

Examples

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

const redis = Redis.fromEnv();

// Push to left (head) of list
await redis.lpush("tasks", "task1");
await redis.lpush("tasks", "task2", "task3"); // ["task3", "task2", "task1"]

// Push to right (tail) of list
await redis.rpush("tasks", "task4"); // ["task3", "task2", "task1", "task4"]

// Get list length
const length = await redis.llen("tasks"); // 4

// Get range of elements (0-based index, inclusive)
const allTasks = await redis.lrange("tasks", 0, -1); // All elements
const firstTwo = await redis.lrange("tasks", 0, 1); // ["task3", "task2"]

// Get element by index
const first = await redis.lindex("tasks", 0); // "task3"
const last = await redis.lindex("tasks", -1); // "task4"

// Set element at index
await redis.lset("tasks", 0, "updated-task");

// Pop from left (head)
const leftItem = await redis.lpop("tasks"); // "updated-task"

// Pop from right (tail)
const rightItem = await redis.rpop("tasks"); // "task4"

// Pop multiple elements from left
await redis.lpush("numbers", 1, 2, 3, 4, 5);
const twoItems = await redis.lpop("numbers", 2); // [5, 4]

// Trim list to specified range (keep only indices 0 to 2)
await redis.ltrim("tasks", 0, 2);

// Remove elements by value
await redis.rpush("items", "a", "b", "c", "b", "d");
await redis.lrem("items", 2, "b"); // Remove first 2 occurrences of "b" from left
// Use negative count to remove from right, 0 to remove all

// Insert before or after a pivot element
await redis.linsert("items", "BEFORE", "c", "x"); // Insert "x" before "c"
await redis.linsert("items", "AFTER", "c", "y"); // Insert "y" after "c"

// Delete entire list
await redis.del("tasks");

Source: SKILL.md on GitHub

1 warning10d3 checks · Risk SAFE
  • Gen Agent Trust Hub10d

    The skill provides a comprehensive set of documentation and code examples for using the Upstash Redis SDK. It covers various data structures, performance optimizations, and search capabilities. No malicious code, obfuscation, or unauthorized data access patterns were detected. The skill uses standard environment variables for secret management and references official Upstash packages.

  • Socket10d

    1 alert: gptSecurity

  • Snyk10d

    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