admin管理员组文章数量:1345734
I am implementing a cacheing layer in NodeJS and MongoDB using Redis. I am fairly new to Redis. So I am having trouble where I am trying to automatically clear cache after a given timing. The error I am getting
ReplyError: ERR wrong number of arguments for 'hset' mand
This is my code block
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;
}
I am implementing a cacheing layer in NodeJS and MongoDB using Redis. I am fairly new to Redis. So I am having trouble where I am trying to automatically clear cache after a given timing. The error I am getting
ReplyError: ERR wrong number of arguments for 'hset' mand
This is my code block
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;
}
Share
Improve this question
asked Jan 4, 2019 at 16:11
Rajesh BarikRajesh Barik
1912 gold badges3 silver badges14 bronze badges
1 Answer
Reset to default 10Redis HSET
only accepts 3 arguments. If you want to store multiple keys in one call, you should use HMSET
.
Reference:
https://redis.io/mands/hset
https://redis.io/mands/hmset
client.hmset(this.hashKey, key, JSON.stringify(result), 'EX', 10);
should work.
本文标签: javascriptHow fix arguments error of HSET in RedisStack Overflow
版权声明:本文标题:javascript - How fix arguments error of HSET in Redis? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743708645a2525549.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论