Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR value is not an integer or out of range with RateLimiterRedis #268

Open
dbersan opened this issue Jun 23, 2024 · 3 comments
Open

ERR value is not an integer or out of range with RateLimiterRedis #268

dbersan opened this issue Jun 23, 2024 · 3 comments

Comments

@dbersan
Copy link

dbersan commented Jun 23, 2024

Redis version: Redis server v=7.2.5 sha=00000000:0 malloc=libc bits=64 build=bd81cd1340e80580

I'm trying to use this rate limiter with nestjs, based on this code:

const redisClient = new Redis()

const limiter = new RateLimiterRedis({
  redis: redisClient,
  useRedisPackage: true,
  keyPrefix: 'login_fail_consecutive_username',
  points: 20,
  duration: 60 * 60 * 24, // Store number for three hours since first fail
});

// ...

async consume = () => {
  return limiter.consume("userId123", 1)
}

I debugged and found the error exactly to be on this like node_modules/rate-limiter-flexible/lib/RateLimiterRedis.js:128 :

     else {
        return this.client.eval(this._incrTtlLuaScript, {
          keys: [rlKey],
          arguments: [String(points), String(secDuration), String(this.points), String(this.duration)],
        });
      }

where:

this._incrTtlLuaScript="redis.call('set', KEYS[1], 0, 'EX', ARGV[2], 'NX') local consumed = redis.call('incrby', KEYS[1], ARGV[1]) local ttl = redis.call('pttl', KEYS[1]) if ttl == -1 then redis.call('expire', KEYS[1], ARGV[2]) ttl = 1000 * ARGV[2] end return {consumed, ttl} "

rlKey="userId123"

points=1

SecDuration=86400

etc...

@dbersan
Copy link
Author

dbersan commented Jun 23, 2024

eval is being called with the wrong argument it seems, where args[1]='[object Object]'

image

@dbersan
Copy link
Author

dbersan commented Jun 23, 2024

It seems just by removing the line useRedisPackage: true, on the configuration solved the issue.

Still, this seems to be a bug on the library.

@animir
Copy link
Owner

animir commented Jun 24, 2024

@dbersan There were two wrong examples in docs. I fixed them, thank you.

useRedisPackage: true flag is for redis package, that's why it doesn't work with ioredis.
Removing this option is the right move.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants