You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Vercel上使用Upstash Redis操作执行后挂起问题求助

Vercel部署后Upstash Redis/QStash偶发挂起问题

本地运行完全正常的代码,部署到Vercel后出现偶发挂起:

  • Upstash Redis监控显示数据有时能成功插入,有时失败
  • Vercel日志显示代码偶尔卡在await语句处

使用环境:

  • 按需付费版Upstash Redis
  • 专业版Vercel
  • 同时使用Upstash QStash,同样存在偶发触发失败、首次调用卡住的问题,本地均正常运行

核心代码

import { Redis } from '@upstash/redis'
const redis = new Redis({
  url: process.env.UPSTASH_REDIS_REST_URL!,
  token: process.env.UPSTASH_REDIS_REST_TOKEN!,
  enableAutoPipelining: true,
  retry: {
    retries: 5,
    backoff: (retryCount) => Math.exp(retryCount) * 50,
  },
})
const result = await Promise.all([
  redis.hset(taskId + '_info', {platform,searchId,collectionId,}),
  redis.rpush(taskId, ...keywords),
  redis.expire(taskId, TASK_EXPIRY_TIME),
  redis.expire(taskId + '_info', TASK_EXPIRY_TIME)
]);

已尝试但无效的解决方案

  • 调整Vercel函数超时时间:在Vercel设置中增加函数执行超时,未解决挂起问题
  • 使用Redis Pipeline:改用Pipeline批量执行命令,仍偶发挂起,代码如下:
const pipeline = redis.pipeline();
pipeline.hset(taskId + '_info', { /* data */ });
pipeline.rpush(taskId, ...keywords);
pipeline.expire(taskId, TASK_EXPIRY_TIME);
pipeline.expire(taskId + '_info', TASK_EXPIRY_TIME);
const results = await pipeline.exec();
  • 切换至ioredis:替换Upstash Redis客户端为ioredis,Serverless环境下仍存在不稳定问题

内容的提问来源于stack exchange,提问作者Anyi Wang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 18:52:34