2

i have an error with redis set command on local redis server(127.0.0.1:6379)

versions:

npm version : 2.15.0;
node version : 4.4.2;
nodejs verison : 0.10.25;
redis version : 2.7.1;

Error:

events.js:141 throw er; // Unhandled 'error' event
ReplyError: ERR wrong number of arguments for 'set' command at parseError 
(/opt/xxx/xxx/node_modules/redis/node_modules/redis 
parser/lib/parser.js:193:12) at parseType 
(/opt/xxx/xxx/node_modules/redis/node_modules/redis-
parser/lib/parser.js:303:14)

all of my codes look like this:

redis.set("key","value")

on my local machine the code is running successfully , but on aws linux machine i got this error.

var matchedMaps = map.get(publicURIField);
            if(matchedMaps) {
                matchedMaps.forEach(function(matchedMap){
                    var patternToValidate = matchedMap.pattern;
                    var type = matchedMap.type;
                    var tagID = matchedMap.tagID;
                    var patternToCheck = "cs-uri-stem";
                    var patternToSave = "";
                    if(type==1){
                        patternToCheck = "c-referrer";
                    }
                    var regexToFind = new RegExp(patternToValidate.substring(1,patternToValidate.length-1));
                    var matchedPattern;
                    if (regexToFind.test(rawLogParsed[patternToCheck].toString())) {
                        if (matchedMap.regexType=="&"){
                            matchedMap.patterns.forEach(function(patternObject){
                                var key = patternObject.pattern.split("=")[0];
                                var value = rawLogParsed[patternToCheck].toString().split(key)[1];
                                if(rawLogParsed[patternToCheck].toString().split(key)[1].split("&")){
                                    value = rawLogParsed[patternToCheck].toString().split(key)[1].split("&")[0];
                                }
                                patternToSave += key+value+"&";
                            });
                        }else{
                            matchedMap.patterns.forEach(function(patternObject){
                                if(patternObject.pattern.indexOf("*")>-1){
                                    patternObject.pattern = patternObject.pattern.replace(/\*!/g, '.*');
                                }
                                patternToSave += rawLogParsed[patternToCheck].toString().match(patternObject.pattern)+"/";
                            });
                        }
                        patternToSave = patternToSave.substring(0,patternToSave.length-1);
                        var matchedField = publicURIField,matchedPattern = patternToSave
                            ,key = tagID + "_"+userID+"_"+ matchedField + "_" + matchedPattern + "_" + type + "_" + fixedMinuteNumber;
                        if (tagUsageInfo[startKeyForRedis+key] == undefined) {
                            var tagObject = {
                                pattern:matchedPattern,
                                matchedField:matchedField,
                                userID:userID,
                                tagName:matchedMap.tagName,
                                monthNumber:parseInt(mMonthToCheck),
                                minuteNumber: parseInt(fixedMinuteNumber),
                                hourNumber: parseInt(yearMonthDayHourToCheck),
                                dayNumber: parseInt(yearMonthDayToCheck),
                                tagID: tagID,
                                matchedPattern: matchedPattern,
                                totalRequests: 1,
                                totalEgress: parseInt(bytes),
                                totalTransfered: parseInt(bytes),
                                totalRest: parseInt(totalWorld),
                                totalUS: parseInt(totalUS)
                            }
                            if(isIngress){
                                tagObject.totalIngres += parseInt(bytes);
                            }
                            dbclient1.set(startKeyForRedis+"tagUsage_"+key,JSON.stringify(tagObject));
                            tagUsageInfo[startKeyForRedis+"tagUsage_"+key] = startKeyForRedis+key;
                        }
                        else {
                            dbclient1.get(startKeyForRedis+"tagUsage_"+key, function(err, tagObject) {
                                var tagObjectJson = JSON.parse(tagObject);
                                tagObjectJson.totalRequests += 1;
                                tagObjectJson.totalEgress += parseInt(bytes);
                                tagObjectJson.totalTransfered += parseInt(bytes);
                                tagObjectJson.totalRest += parseInt(totalWorld);
                                tagObjectJson.totalUS += parseInt(totalUS);
                                tagObjectJson.totalRequests += 1;
                                if(isIngress){
                                    tagObject.totalIngres += parseInt(bytes);
                                }
                                dbclient1.del(startKeyForRedis+"tagUsage_"+key);
                                dbclient1.set(startKeyForRedis+"tagUsage_"+key, JSON.stringify(tagObjectJson));
                            });
                        }
                    }
                });
            }

any help?

3
  • 3
    Code or it didn't happen. Commented Apr 25, 2017 at 11:35
  • Doesn't the message tell you the problem? wrong number of arguments Commented Apr 25, 2017 at 11:41
  • its cant be, because all of my code is redis.set(key,value); key = type string , value = JSON.stringify(JSON) Commented Apr 25, 2017 at 11:50

6 Answers 6

10

1)If your trying to run redis on windows set accepts only two arguments cause the redis version issue

2)try latest version of redis on linux it will work

Sign up to request clarification or add additional context in comments.

Comments

3

Try installing this version of Redis on windows from the following link. You can find more information here https://github.com/ServiceStack/redis-windows

This link provides three options to install Redis on windows

Option 1) Install Redis on Ubuntu on Windows

Option 2) Running the latest version of Redis with Vagrant

Option 3) Running Microsoft's native port of Redis

I personally prefer option 3. Hope this helped. Thanks.

Comments

2

all of my codes look like this: [...]

It's not important how all of your code looks like. It's important how the specific line that caused the problem looks like but unfortunately you didn't include it.

The errors that you provided include some files and line numbers but you seem to have removed the ones that are related to your code. If you read those messages carefully then you should be able to know what lines those errors are related to and focus on those lines.

If the errors show up on a server and not on your desktop then I would suspect that maybe you're trying to use some environment variables or files on the file system to populate some variables in your program, and those are not available on the server resulting in putting undefined there.

You will surely find the problem when you add console.log() statements to every place where you want to access Redis so that you first print it and then call to Redis. That way at least you will know what data is causing the problem. I suspect that you are having some undefined values or something like that.

Remember that JSON.stringify(undefined) returns undefined instead of a valid JSON string. Something like that may be causing problems. Adding debug messages will help to narrow it down.

Some extra advice: You can use prefix parameter of the redis module then you will not have to add startKeyForRedis+ all over the place. You can set a prefix once and have it prepended automatically. See the docs:

2 Comments

thanks for the answer, but when i run the same code on local machine its working and running. on aws machine (linux) he stuck with this error...
thanks, its working, it is because in local system var was not undefined, but in the remote server it was undefined, thanks for the help.
0

I was doing learning to use KUE a nodejs library for job scheduling that uses redis for saving data. I got this error while running client.js(that puts jobs in queue) and worker.js(that process the schedule jobs). I was running worker before running the client and that is why this happened. I reversed the order and everything went fine!

Comments

0

To fix this error on windows Redis from v.3 required. That's why I've took zipped release 3.0.504 from here and now all is working.

Quite simple.

Comments

0

I have faced similar type of error which was because of older version of Redis. This is compatibility issue which fixes a bug in Redis after Redis 2.6.12. Make sure you install recent version of Redis v3.X.

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.