小编Raj*_*rik的帖子

有人可以解释这个错误:表达式语句不是赋值或调用

我有这两块代码。

socket.on('chatMessage', function(message) {
    message.type = 'message';
    message.created = Date.now();
    message.username : socket.request.user.username;
});

socket.on('disconnect', function() {
    io.emit('chatMessage', {
        type: 'status',
        text: socket.request.user.username + ' left the conversation.',
        created: Date.now(),
        username: socket.request.user.username,
    });
});
Run Code Online (Sandbox Code Playgroud)

如果我更改:或更改=为其他,Webstorm 会给我错误。Expression statement is not assignment or call.有人可以解释为什么会发生这种情况吗?提前致谢。

node.js socket.io

3
推荐指数
1
解决办法
1万
查看次数

如何修复Redis中HSET的参数错误?

我正在使用 Redis 在 NodeJS 和 MongoDB 中实现缓存层。我对Redis相当陌生。所以我在尝试在给定时间后自动清除缓存时遇到了麻烦。我得到的错误

ReplyError: ERR wrong number of arguments for 'hset' command
Run Code Online (Sandbox Code Playgroud)

这是我的代码块

mongoose.Query.prototype.exec = async function() {

  const key = JSON.stringify(
      Object.assign({}, this.getQuery(), {collection: 
      this.mongooseCollection.name})
  );
  const cachedValue = await client.hget(this.hashKey, key);

  if(cachedValue) {
      const parsedDoc = JSON.parse(cachedValue);

      return Array.isArray(parsedDoc) ? parsedDoc.map(doc => new 
      this.model(doc)) : new this.model(parsedDoc);
  }

  const result = await exec.apply(this, arguments);

  client.hset(this.hashKey, key, JSON.stringify(result), 'EX', 10);

  return result;
}
Run Code Online (Sandbox Code Playgroud)

javascript redis node.js

2
推荐指数
1
解决办法
4813
查看次数

标签 统计

node.js ×2

javascript ×1

redis ×1

socket.io ×1