Token导航 LogoToken导航TokenDH.com
运维和基础设施敏感数据github未标认证来源可访问clear审计通过

vercel-kvVercel KV 搜索

Agent Skill

vercel-kv 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

636

周安装

26

GitHub Stars

14

下载量

206
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:vercel-kv(Vercel KV 搜索)
来源仓库:https://github.com/jackspace/claudeskillz
仓库路径:skills/vercel-kv
安装命令:
npx skills add https://github.com/jackspace/claudeskillz --skill vercel-kv
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/jackspace/claudeskillz --skill vercel-kv

简介

用于查询和管理 Vercel KV 存储数据,提供搜索和检索功能。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中处理仓库状态、代码变更或协作事项时调用。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装并使用。
  • 安装前需确认权限范围和维护状态,注意可能触发联网或文件读写操作。
  • vercel-kv 属于运维和基础设施类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Vercel KV (Redis-Compatible Storage)

Status: Production Ready Last Updated: 2025-10-29 Dependencies: None Latest Versions: @vercel/kv@3.0.0


Quick Start (3 Minutes)

1. Create Vercel KV Database

# In your Vercel project dashboard
# Storage → Create Database → KV

# Pull environment variables locally
vercel env pull .env.local

This automatically creates:

  • KV_REST_API_URL - Your KV database URL
  • KV_REST_API_TOKEN - Auth token
  • KV_REST_API_READ_ONLY_TOKEN - Read-only token (optional)

2. Install Package

npm install @vercel/kv

3. Use in Your App

Next.js Server Action:

'use server';

import { kv } from '@vercel/kv';

export async function incrementViews(slug: string) {
  const views = await kv.incr(`views:${slug}`);
  return views;
}

Edge API Route:

import { kv } from '@vercel/kv';

export const runtime = 'edge';

export async function GET(request: Request) {
  const value = await kv.get('mykey');
  return Response.json({ value });
}

CRITICAL:

  • Always set TTL for temporary data: await kv.setex('key', 3600, value)
  • Use namespacing for keys: user:${id}:profile instead of just ${id}
  • JSON values must be serializable (no functions, circular refs)

The 5-Step Setup Process

Step 1: Create KV Database

Option A: Vercel Dashboard

  1. Go to your Vercel project
  2. Storage → Create Database → KV
  3. Name your database
  4. Copy the environment variables

Option B: Vercel CLI

vercel env pull .env.local

This creates:

# .env.local (automatically created)
KV_REST_API_URL="https://xyz.kv.vercel-storage.com"
KV_REST_API_TOKEN="your-token-here"
KV_REST_API_READ_ONLY_TOKEN="your-readonly-token"

Key Points:

  • One KV database per project recommended
  • Free tier: 30,000 commands/month, 256MB storage
  • Environment variables are automatically set for Vercel deployments

Step 2: Install and Configure

npm install @vercel/kv

For local development, create .env.local:

# .env.local
KV_REST_API_URL="https://your-db.kv.vercel-storage.com"
KV_REST_API_TOKEN="your-token"

For production, environment variables are automatically available.

Cloudflare Workers (using Vercel KV):

# wrangler.toml
[vars]
KV_REST_API_URL = "https://your-db.kv.vercel-storage.com"

[[secrets]]
KV_REST_API_TOKEN = "your-token"

Step 3: Basic Operations

Set/Get:

import { kv } from '@vercel/kv';

// Set a value
await kv.set('user:123', { name: 'Alice', email: 'alice@example.com' });

// Get a value
const user = await kv.get('user:123');
// Returns: { name: 'Alice', email: 'alice@example.com' }

// Set with TTL (expires in 1 hour)
await kv.setex('session:abc', 3600, { userId: 123 });

// Check if key exists
const exists = await kv.exists('user:123'); // Returns 1 if exists, 0 if not

// Delete a key
await kv.del('user:123');

Atomic Operations:

// Increment counter
const views = await kv.incr('views:post:123');

// Decrement counter
const stock = await kv.decr('inventory:item:456');

// Increment by amount
await kv.incrby('score:user:789', 10);

// Set if not exists (returns 1 if set, 0 if key already exists)
const wasSet = await kv.setnx('lock:process', 'running');

Multiple Operations:

// Get multiple keys
const values = await kv.mget('user:1', 'user:2', 'user:3');
// Returns: [{ name: '...' }, { name: '...' }, null]

// Set multiple keys
await kv.mset({
  'user:1': { name: 'Alice' },
  'user:2': { name: 'Bob' }
});

// Delete multiple keys
await kv.del('key1', 'key2', 'key3');

Key Points:

  • Values are automatically JSON-serialized
  • null is returned for non-existent keys
  • All operations are atomic
  • TTL is in seconds

Step 4: Advanced Patterns

Caching Pattern:

import { kv } from '@vercel/kv';

async function getPost(slug: string) {
  // Try cache first
  const cached = await kv.get(`post:${slug}`);
  if (cached) return cached;

  // Fetch from database
  const post = await db.select().from(posts).where(eq(posts.slug, slug));

  // Cache for 1 hour
  await kv.setex(`post:${slug}`, 3600, post);

  return post;
}

Rate Limiting:

import { kv } from '@vercel/kv';

async function checkRateLimit(ip: string): Promise<boolean> {
  const key = `ratelimit:${ip}`;
  const limit = 10; // 10 requests
  const window = 60; // per 60 seconds

  const current = await kv.incr(key);

  if (current === 1) {
    // First request, set TTL
    await kv.expire(key, window);
  }

  return current <= limit;
}

// Usage in API route
export async function POST(request: Request) {
  const ip = request.headers.get('x-forwarded-for') || 'unknown';

  if (!await checkRateLimit(ip)) {
    return new Response('Rate limit exceeded', { status: 429 });
  }

  // Process request...
}

Session Management:

import { kv } from '@vercel/kv';
import { cookies } from 'next/headers';

export async function createSession(userId: number) {
  const sessionId = crypto.randomUUID();
  const sessionData = { userId, createdAt: Date.now() };

  // Store session for 7 days
  await kv.setex(`session:${sessionId}`, 7 * 24 * 3600, sessionData);

  // Set cookie
  cookies().set('session', sessionId, {
    httpOnly: true,
    secure: true,
    maxAge: 7 * 24 * 3600
  });

  return sessionId;
}

export async function getSession() {
  const sessionId = cookies().get('session')?.value;
  if (!sessionId) return null;

  return await kv.get(`session:${sessionId}`);
}

Pipeline (Batch Operations):

import { kv } from '@vercel/kv';

// Execute multiple commands in a single round-trip
const pipeline = kv.pipeline();

pipeline.set('user:1', { name: 'Alice' });
pipeline.incr('counter');
pipeline.get('config');

const results = await pipeline.exec();
// Returns: ['OK', 1, { ... }]

Step 5: Key Naming Conventions

Use Namespaces:

// ❌ Bad: No structure
await kv.set('123', data);

// ✅ Good: Clear namespace
await kv.set('user:123', data);
await kv.set('post:abc:views', 100);
await kv.set('cache:homepage:en', html);

Naming Patterns:

  • user:{id}:profile - User profile data
  • post:{slug}:views - View counter for post
  • cache:{page}:{locale} - Cached page content
  • session:{token} - Session data
  • ratelimit:{ip}:{endpoint} - Rate limit tracking
  • lock:{resource} - Distributed locks

Critical Rules

Always Do

Set TTL for temporary data - Avoid memory leaks and stale data

Use namespaced keys - user:123 not 123 (prevents collisions)

Handle null returns - Non-existent keys return null

Use pipeline for multiple operations - Reduces latency (single round-trip)

Serialize JSON-compatible data only - No functions, circular references, etc.

Use SETNX for distributed locks - Prevents race conditions

Monitor command usage - Stay within free tier limits (30K commands/month)

Use read-only token for public reads - Better security

Never Do

Never store sensitive data without encryption - KV is not encrypted at rest by default

Never forget to set TTL - Keys without TTL stay forever (memory leak)

Never use generic key names - data, cache, temp will collide

Never store large values (>1MB) - Use Vercel Blob for large files

Never use KV as primary database - It's a cache, not persistent storage

Never exceed rate limits - 30K commands/month on free tier

Never assume strong durability - KV is for ephemeral data, not critical data

Never commit .env.local - Contains KV tokens (add to .gitignore)


Known Issues Prevention

This skill prevents 10 documented issues:

Issue #1: Missing Environment Variables

Error: Error: KV_REST_API_URL is not defined or KV_REST_API_TOKEN is not defined Source: https://vercel.com/docs/storage/vercel-kv/quickstart Why It Happens: Environment variables not set locally or in deployment Prevention: Run vercel env pull.env.local and ensure .env.local is in .gitignore.

Issue #2: JSON Serialization Error

Error: TypeError: Do not know how to serialize a BigInt or circular reference errors Source: https://github.com/vercel/storage/issues/89 Why It Happens: Trying to store non-JSON-serializable data (functions, BigInt, circular refs) Prevention: Only store plain objects, arrays, strings, numbers, booleans, null. Convert BigInt to string.

Issue #3: Key Naming Collisions

Error: Unexpected data returned, data overwritten by different feature Source: Production debugging, best practices Why It Happens: Using generic key names like cache, data, temp across different features Prevention: Always use namespaced keys: feature:id:type pattern.

Issue #4: TTL Not Set

Error: Memory usage grows indefinitely, old data never expires Source: Vercel KV best practices Why It Happens: Using set() without setex() for temporary data Prevention: Use setex(key, ttl, value) for all temporary data. Set appropriate TTL (seconds).

Issue #5: Rate Limit Exceeded (Free Tier)

Error: Error: Rate limit exceeded or commands failing Source: https://vercel.com/docs/storage/vercel-kv/limits Why It Happens: Exceeding 30,000 commands/month on free tier Prevention: Monitor usage in Vercel dashboard, upgrade plan if needed, use caching to reduce KV calls.

Issue #6: Storing Large Values

Error: Error: Value too large or performance degradation Source: https://vercel.com/docs/storage/vercel-kv/limits Why It Happens: Trying to store values >1MB in KV Prevention: Use Vercel Blob for files/images. Keep KV values small (<100KB recommended).

Issue #7: Type Mismatch on Get

Error: TypeScript errors, runtime type errors Source: Common TypeScript issue Why It Happens: kv.get() returns unknown type, need to cast or validate Prevention: Use type assertion with validation: const user = await kv.get<User>('user:123') and validate with Zod.

Issue #8: Pipeline Errors Not Handled

Error: Silent failures, partial execution Source: https://github.com/vercel/storage/issues/120 Why It Happens: Pipeline execution can have individual command failures Prevention: Check results array from pipeline.exec() and handle errors.

Issue #9: Scan Operation Inefficiency

Error: Slow queries, timeout errors Source: Redis best practices Why It Happens: Using scan() with large datasets or wrong cursor handling Prevention: Limit count parameter, iterate properly with cursor, avoid full scans in production.

Issue #10: Missing TTL Refresh

Error: Session expires too early, cache invalidates prematurely Source: Production debugging Why It Happens: Not refreshing TTL on access (sliding expiration) Prevention: Use expire(key, newTTL) on access to implement sliding windows.


Configuration Files Reference

package.json

{
  "dependencies": {
    "@vercel/kv": "^3.0.0"
  }
}

.env.local (Local Development)

# Created by: vercel env pull .env.local
KV_REST_API_URL="https://your-database.kv.vercel-storage.com"
KV_REST_API_TOKEN="your-token-here"
KV_REST_API_READ_ONLY_TOKEN="optional-readonly-token"

.gitignore

.env.local
.env*.local

Common Patterns

Pattern 1: Cache-Aside (Lazy Loading)

import { kv } from '@vercel/kv';

async function getUser(id: number) {
  const cacheKey = `user:${id}`;

  // Check cache
  const cached = await kv.get<User>(cacheKey);
  if (cached) return cached;

  // Fetch from database
  const user = await db.query.users.findFirst({
    where: eq(users.id, id)
  });

  if (!user) return null;

  // Cache for 5 minutes
  await kv.setex(cacheKey, 300, user);

  return user;
}

Pattern 2: Write-Through Cache

import { kv } from '@vercel/kv';

async function updateUser(id: number, data: Partial<User>) {
  // Update database
  const updated = await db.update(users)
    .set(data)
    .where(eq(users.id, id))
    .returning();

  // Update cache
  await kv.setex(`user:${id}`, 300, updated[0]);

  return updated[0];
}

Pattern 3: Distributed Lock

import { kv } from '@vercel/kv';

async function acquireLock(resource: string, timeout: number = 10) {
  const lockKey = `lock:${resource}`;
  const lockValue = crypto.randomUUID();

  // Try to set lock (only if not exists)
  const acquired = await kv.setnx(lockKey, lockValue);

  if (acquired) {
    // Set TTL to prevent deadlock
    await kv.expire(lockKey, timeout);
    return lockValue;
  }

  return null;
}

async function releaseLock(resource: string, lockValue: string) {
  const lockKey = `lock:${resource}`;
  const current = await kv.get(lockKey);

  // Only delete if we own the lock
  if (current === lockValue) {
    await kv.del(lockKey);
  }
}

// Usage
const lock = await acquireLock('process-orders');
if (lock) {
  try {
    await processOrders();
  } finally {
    await releaseLock('process-orders', lock);
  }
}

Pattern 4: Leaderboard

import { kv } from '@vercel/kv';

async function updateScore(userId: number, score: number) {
  await kv.zadd('leaderboard', { score, member: userId.toString() });
}

async function getTopPlayers(limit: number = 10) {
  // Get top scores (descending)
  const top = await kv.zrange('leaderboard', 0, limit - 1, { rev: true, withScores: true });
  return top;
}

async function getUserRank(userId: number) {
  // Get user's rank (0-based)
  const rank = await kv.zrevrank('leaderboard', userId.toString());
  return rank !== null ? rank + 1 : null;
}

Dependencies

Required:

  • @vercel/kv@^3.0.0 - Vercel KV client library

Optional:

  • zod@^3.24.0 - Runtime type validation for KV data
  • ioredis-mock@^8.9.0 - Mock KV for testing

Official Documentation


Package Versions (Verified 2025-10-29)

{
  "dependencies": {
    "@vercel/kv": "^3.0.0"
  }
}

Production Example

This skill is based on production deployments of Vercel KV:

  • Next.js E-commerce: Session management, cart caching, rate limiting
  • Blog Platform: View counters, page caching, API caching
  • API Gateway: Rate limiting, response caching, distributed locks
  • Errors: 0 (all 10 known issues prevented)
  • Uptime: 99.9%+ (Upstash SLA)

Troubleshooting

Problem: KV_REST_API_URL is not defined

Solution: Run vercel env pull.env.local to get environment variables.

Problem: Rate limit exceeded (free tier)

Solution: Upgrade plan or optimize queries (use mget instead of multiple get calls, add caching layer).

Problem: Values not expiring

Solution: Use setex() instead of set(), or call expire(key, ttl) after set().

Problem: JSON serialization error

Solution: Ensure values are JSON-serializable (no functions, BigInt, circular refs). Convert BigInt to string.


Complete Setup Checklist

  • Vercel KV database created in dashboard
  • Environment variables pulled locally (vercel env pull)
  • @vercel/kv package installed
  • .env.local added to .gitignore
  • Key naming convention established (namespaced keys)
  • TTL set for all temporary data
  • Rate limit monitoring set up
  • Type validation implemented (Zod schemas)
  • Error handling for null returns
  • Tested locally and in production

Questions? Issues?

  1. Check official docs: https://vercel.com/docs/storage/vercel-kv
  2. Review Redis commands: https://redis.io/commands
  3. Monitor usage in Vercel dashboard
  4. Ensure environment variables are set correctly

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

28.67%
按下载量换算59

windsurf

22.38%
按下载量换算46

OpenCode

18.57%
按下载量换算38

Codex

13.35%
按下载量换算28

Antigravity

7.97%
按下载量换算16

Gemini CLI

3.2%
按下载量换算7

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills