1

I am using redis list for storing the value for a key in nodeJS. I have made the following function and exported it to another file to make it a api:

async function set(id, ...seats) {
    var seatArr = [];
    for(var i = 0; i < seats.length; i++)
    {
        seatArr = seatArr.concat(seats[i]);
    }
    try{
        result = await client.rpush('seats_'+id, ...seatArr);
    } catch(err) {
        console.log(err)
    }

}
module.exports = {
    set : set()
};

But I am getting the following error:

{ ReplyError: ERR wrong number of arguments for 'rpush' command
    at parseError (/home/shivank/Music/node-app/ticket-booking/node_modules/redis-parser/lib/parser.js:179:12)
    at parseType (/home/shivank/Music/node-app/ticket-booking/node_modules/redis-parser/lib/parser.js:302:14) command: 'RPUSH', args: [ 'seats_undefined' ], code: 'ERR' }

Please help me to resolve this.

2
  • 1
    Is your goal to rpush for every item in the array? Seems to be two issues, id is undefined but this isn't why it's breaking, you can see that there is only one argument being passed to RPUSH your ...seatArr must be empty Commented Apr 10, 2020 at 11:32
  • @razki yeah seatArr is empty because I haven't called that function yet. I am just exporting that function. But I want to wait until the function is called. Is there a way to do that? Commented Apr 10, 2020 at 14:05

1 Answer 1

1

Problem

You are not exproting a function, you are trying to export the result of the function (which files because you didn't provide the params that it needs).

module.exports = {
    set : set().   // <<<---- You are executing the function
};

but you didn't give it any params so the id param is equal to undefined.

From your stacktrace:

..[ 'seats_undefined' ].. // 'seats_'+id === 'seats_'+`undefined` === 'seats_undefined'

Solution

module.exports = {
    set : set
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.