我有这两块代码。
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.有人可以解释为什么会发生这种情况吗?提前致谢。
我正在使用 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)