Ioredis: brpop receive one params, but run error:ReplyError: ERR wrong number of arguments for 'brpop' command

Created on 28 Apr 2019  路  5Comments  路  Source: luin/ioredis

env:
nodejs : 10.12.0
redis: 5.0.1 sentinels cluster

code:
import { CallbackFunction, RedisOptions } from "ioredis"
import * as IORedis from "ioredis"
const clientMap: { [channel: string]: IORedis.Redis } = {}

const getClient = (channel: string) => {
if (!(channel in clientMap))
clientMap[channel] = new IORedis(connOptions)
return clientMap[channel]
}

brpop: (key: string[]) => {
return getClient("list").brpop(...key)
}

but I check the ts package index.d.ts:
brpop(...keys: KeyType[]): any;

i'm sure the params is correct.

when I call the brpop function, it's error:
(node:12812) UnhandledPromiseRejectionWarning: ReplyError: ERR wrong number of arguments for 'brpop' command
at parseError (/Users/zhoujie/Projects/notify_server/node_modules/ioredis/node_modules/redis-parser/lib/parser.js:179:12)
at parseType (/Users/zhoujie/Projects/notify_server/node_modules/ioredis/node_modules/redis-parser/lib/parser.js:302:14)
(node:12812) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

wontfix

Most helpful comment

I just ran into this problem. These are the type definitions for blpop and brpop.

        brpop(...keys: KeyType[]): any;
        blpop(...keys: KeyType[]): any;

These methods require a timeout value. What's not obvious, is that you need to supply this as a string. Example:

const result = await brpop("mykey", "30");

Where 30 is the timeout in seconds.

All 5 comments

env:
nodejs : 10.12.0
redis: 5.0.1 sentinels cluster

code:
import { CallbackFunction, RedisOptions } from "ioredis"
import * as IORedis from "ioredis"
const clientMap: { [channel: string]: IORedis.Redis } = {}

const getClient = (channel: string) => {
if (!(channel in clientMap))
clientMap[channel] = new IORedis(connOptions)
return clientMap[channel]
}

brpop: (key: string[]) => {
return getClient("list").brpop(...key)
}

but I check the ts package index.d.ts:
brpop(...keys: KeyType[]): any;

i'm sure the params is correct.

when I call the brpop function, it's error:
(node:12812) UnhandledPromiseRejectionWarning: ReplyError: ERR wrong number of arguments for 'brpop' command
at parseError (/Users/zhoujie/Projects/notify_server/node_modules/ioredis/node_modules/redis-parser/lib/parser.js:179:12)
at parseType (/Users/zhoujie/Projects/notify_server/node_modules/ioredis/node_modules/redis-parser/lib/parser.js:302:14)
(node:12812) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

I believe brpop command minimum of 2 arguments:

  1. Key/ [key ...]
  2. timeout : brpop will wait for that time if it does not get anything to rpop then will exit. If passed 0 will wait until one push happens to the key.

Plz refer documentation as below:
https://redis.io/commands/blpop

Try passing 0 if you want infinite block r else pass some timeout in ms, if you want to block till that time.
Screenshot 2019-04-29 at 11 05 12 AM

wait updating...

wait updating...

By Passing a 2nd argument as 0/some timeout didn't work out? @No1Jie

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 7 days if no further activity occurs, but feel free to re-open a closed issue if needed.

I just ran into this problem. These are the type definitions for blpop and brpop.

        brpop(...keys: KeyType[]): any;
        blpop(...keys: KeyType[]): any;

These methods require a timeout value. What's not obvious, is that you need to supply this as a string. Example:

const result = await brpop("mykey", "30");

Where 30 is the timeout in seconds.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

haoxins picture haoxins  路  5Comments

AdriVanHoudt picture AdriVanHoudt  路  4Comments

snig-b picture snig-b  路  5Comments

ORESoftware picture ORESoftware  路  5Comments

saschaishikawa picture saschaishikawa  路  4Comments