title: Why is my res.send({message:"Hi"}); showing Error: node_redis: The SET command contains a invalid argument type error?
body: <p>I have a trouble something which I cannot understand absolutely.</p>
  <p>I send such fetch request from React to Expressjs server</p>
  <pre><code>    fetch('//localhost:8000/auth/checkLoginStatus',{
      method:'GET',
      credentials:'include',
      headers:{
          'Accept':'application/json',
          'Content-Type':'application/json'
      },
  }).then((data)=&gt;{
      return data.json();
  }).then((data)=&gt;{
      console.log(data);
      console.log(JSON.stringify(data).length);
      if(JSON.stringify(data)[0]){
          debugger;
      }   
  });
  </code></pre>
  <p>So as you see in fetch URL, I send a request to <em>'localhost:8000/auth/checkLoginStatus'</em></p>
  <p>This is my main express.js code</p>
  <pre><code>//main javascript file for nodejs. server
  
  const express = require('express');
  const session = require('express-session');
  const app = express();
  const port = 8000;
  const cors =require('cors');
  const bodyParser = require('body-parser');
  const cookieParser = require('cookie-parser');
  const chatRouter = require('./router/chatRouter.js');
  const authRouter = require('./router/authRouter.js');
  const redis = require ('./redis/redis');
  const { RedisClient } = require('redis');
  const redisStore= require('connect-redis')(session);
  require('dotenv').config();
  //cors setting
  app.use(cors({
    origin:'http://localhost:8081',
    credentials:true
  }));
  app.use(express.urlencoded({extended: true}));
  app.use(express.json());
  app.use(cookieParser());
  //redis
  const createdClientRedis = redis.createRedisClient();
  app.use(
    session({
      resave:false,
      name:'user',
      saveUninitialized:true,
      secret:process.env.redis_secret_key,
      cookie:{
        httpOnly:true,
        secure:false
      },
      store:new RedisClient({createdClientRedis})
    })
  );
  
  //Routers
  app.use('/chat',chatRouter);
  app.use('/auth',authRouter);
  app.listen(port, () =&gt; {
    console.log(`Example app listening on port ${port}!`)
  });
  </code></pre>
  <p>With router, my request will be handled in authRouter. And code below is code in authRouter.js</p>
  <pre><code>const express = require('express');
  const router = express.Router();
  const dbFile = require('../userListDB');
  const cookie = require('../cookie-session/cookie');
  const redis = require('../redis/redis.js');
  router.use(express.json());
  
  //if login POST request is sent from client
  router.post('/login',(req,res)=&gt;{
      dbFile.checkIfUserExists(req.body.userId,'login')
      .then(()=&gt;{
          return dbFile.loginSQL(req);
        }).then((data)=&gt;{
          return dbFile.comparePWtoEncryptedPassword(data);
        }).then((data)=&gt;{
          redis.setRedis(req);
          res.send({
            errorMessage:''
          });
        })
        .catch((errMessage)=&gt;{
          dbFile.sendDBError(res,errMessage);
        })
  });
  
  router.get(&quot;/checkLogInStatus&quot;,(req,res)=&gt;{
    console.log(&quot;cookie &quot;+req.cookies['user']);
    console.log(&quot;session &quot;+req.session.id);
    res.send({message:&quot;hi&quot;});
  });
  router.post(&quot;/signOut&quot;,(req,res)=&gt;{
    return new Promise((resolve,rejct)=&gt;{
      redis.removeDataFromRedis(req);
      resolve(res);
    })
    .then((res)=&gt;{
      cookie.removeCookie(res);
      return res;
    })
    .then(res=&gt;{
      res.status(200).send(&quot;signed out&quot;);
    })
  })
  //if register POST request sent from client
  router.post('/register',(req,res)=&gt;{
    const userId = req.body.userId;
    const userPw = req.body.userPW;
    const userFirstName = req.body.userFirstName;
    const userAfterName = req.body.userAfterName;
    const userPwConfirm = req.body.pwConfirm;
    try{
      if(/\d/.test(userFirstName)||/\d/.test(userAfterName)){
        throw &quot;First name and after name shouldn't contain number&quot;;
      }
      if(userId.length&lt;5&amp;&amp;userPw.length&lt;5){
        throw &quot;Id and password must be minimum 5 characters&quot;;
      }else if(userId.length&gt;=5&amp;&amp;userPw.length&lt;5){
        throw &quot;Password must be minimum 5 characters&quot;;
      }else if(userId.length&lt;5&amp;&amp;userPw.length&gt;=5){
        throw &quot;Id must be minimum 5 characters&quot;;
      }
      if(userPw!=userPwConfirm){
        throw &quot;Password confirmation wrong&quot;;
      }else{
        dbFile.checkIfUserExists(userId,'register')
        .then((response)=&gt;{
          return dbFile.registerNewUser(req.body);
        }).then((data)=&gt;{
          res.send({
            errorMessage:''
          })
        }).catch((errMessage)=&gt;{
          console.log(errMessage);
          dbFile.sendDBError(res,errMessage);
        });
      }
    }
    catch(e){
      dbFile.sendDBError(res,e);
    }
  });
  module.exports=router;
  </code></pre>
  <p>Problem is in router.get('/checkLoginStatus').
  res.send inside function throws such errors:</p>
  <blockquote>
  <p>Error: node_redis: The SET command contains a invalid argument type.
  Only strings, dates and buffers are accepted. Please update your code to use valid argument types.</p>
  </blockquote>
  <pre><code>at RedisClient.internal_send_command (/mnt/c/xampp/htdocs/ReactFromScratch/chatting-app/server/node_modules/redis/index.js:835:39)
  at RedisClient.set (/mnt/c/xampp/htdocs/ReactFromScratch/chatting-app/server/node_modules/redis/lib/commands.js:46:25)    at Session.save (/mnt/c/xampp/htdocs/ReactFromScratch/chatting-app/server/node_modules/express-session/session/session.js:72:25)
  at Session.save (/mnt/c/xampp/htdocs/ReactFromScratch/chatting-app/server/node_modules/express-session/index.js:406:15)
  at ServerResponse.end (/mnt/c/xampp/htdocs/ReactFromScratch/chatting-app/server/node_modules/express-session/index.js:335:21)
  at ServerResponse.send (/mnt/c/xampp/htdocs/ReactFromScratch/chatting-app/server/node_modules/express/lib/response.js:221:10)
  at ServerResponse.json (/mnt/c/xampp/htdocs/ReactFromScratch/chatting-app/server/node_modules/express/lib/response.js:267:15)
  at ServerResponse.send (/mnt/c/xampp/htdocs/ReactFromScratch/chatting-app/server/node_modules/express/lib/response.js:158:21)
  at router.get (/mnt/c/xampp/htdocs/ReactFromScratch/chatting-app/server/src/router/authRouter.js:29:7)
  at Layer.handle [as handle_request] (/mnt/c/xampp/htdocs/ReactFromScratch/chatting-app/server/node_modules/express/lib/router/layer.js:95:5)
  </code></pre>
  <p>authRouter.js29:7 is equal to res.send().
  Of course if I remove the code line, the error is gone.</p>
  <p><a href="https://i.stack.imgur.com/mCcPM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mCcPM.png" alt="enter image description here" /></a></p>
  <p>What's wrong with my code?</p>
  <p>This is my redis code. I think this is redis which is causing problem because error message shows something about RedisClient too.</p>
  <pre><code>//file which is used to control redis database
  
  const redis = require('redis');
  let redisClient
  module.exports={
      //app.js 에서 사용 
      createRedisClient:function(){
          redisClient = redis.createClient({
              host:&quot;127.0.0.1&quot;,
              port:&quot;6379&quot;,
              db:0
          });
          redisClient.on('error',function(err){
              console.log('Redis Error :'+err);
          });
      },
      //authRouter.js에서 사용
      setRedis:function(req){
          redisClient.set(req.sessionID,req.body.userId);
      },
      getRedis:function(req){
          console.log(&quot;get redis&quot;);
          redisClient.get(req.sessionID,function(err,value){
              console.log(&quot;redis returned :&quot;+value);
          });
      },
      removeDataFromRedis:function(req){
          redisClient.flushall();//just for debugging...
      }
  </code></pre>
  <p>}</p>