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

编程入门 行业动态 更新时间:2024-10-05 19:14:21

Lua redis() 命令参数必须是字符串或<a href=https://www.elefans.com/category/jswz/34/1771264.html style=整数"/>

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'

回答如下:

更多推荐

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

本文发布于:2024-05-30 08:12:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770288.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   字符串   命令   参数   Lua

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!