最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Lua redis() 命令参数必须是字符串或整数

网站源码admin41浏览0评论

Lua redis() 命令参数必须是字符串或整数

Lua redis() 命令参数必须是字符串或整数

我正在使用

应用速率限制
const redis = require('redis');
const { RateLimiterRedis } = require('rate-limiter-flexible');

这是我的代码

  / Create a Redis client
const redisClient = redis.createClient({
  host: 'localhost', // Replace with your Redis server hostname
  port: 6379 // Replace with your Redis server port

});
// Define rate limiting options
const rateLimitOptions = {
  storeClient: redisClient,
  keyPrefix: 'rate-limiter:',
  points: 10, // Number of points a user can accumulate before getting rate limited
  duration: 60, // Time window in seconds
  blockDuration: 60 // Time in seconds for which a user will be blocked after getting rate limited
};

// Create a rate limiter instance
const rateLimiter = new RateLimiterRedis(rateLimitOptions);
// Express middleware to enforce rate limiting
const rateLimitMiddleware = async (req, res, next) => {
  const ip = req.connection.remoteAddress; // Get the user's IP address
  const url = req.originalUrl; // Get the URL of the request
  const key = `${url}_${ip}`;// Use a combination of IP and URL as the key
  try {
    const rateLimiterRes = await rateLimiter.consume(key); // Pass the key and points as arguments
    next(); // Call next() to proceed to the next middleware or route handler
  } catch (rejRes) {
    // Handle rate limit exceeded
    const remainingTime = Math.ceil(rejRes.msBeforeNext / 1000);

这行给我错误 Lua redis() 命令参数必须是字符串或整数\

 const rateLimiterRes = await rateLimiter.consume(key); // Pass the key and points as arguments

我传递的密钥是'/v2.0/json/login-user_::1'

回答如下:
发布评论

评论列表(0)

  1. 暂无评论