Node.js redis和watch+;多允许并发用户
我正在对使用相同电子邮件地址注册Web服务的用户进行负载测试,同时连接的前10个用户将始终注册 我用的是手表和多媒体,但这似乎没有任何效果 我正在调用save()来保存用户Node.js redis和watch+;多允许并发用户,node.js,transactions,load,redis,Node.js,Transactions,Load,Redis,我正在对使用相同电子邮件地址注册Web服务的用户进行负载测试,同时连接的前10个用户将始终注册 我用的是手表和多媒体,但这似乎没有任何效果 我正在调用save()来保存用户 this.insert = function(callback) { this.preInsert(); created = new Date(); updated = new Date(); // Also with these uncommented it still doesn't
this.insert = function(callback) {
this.preInsert();
created = new Date();
updated = new Date();
// Also with these uncommented it still doesn't work
// Common.client.watch("u:" + this.username);
// Common.client.watch("em:" + this.email);
console.log(ID + " email is locked " + this.email);
Common.client.multi()
.set("u:" + this.username, ID)
.hmset("u:" + ID,
{"username": this.username
,"password": this.password
,"email": this.email
,"payment_plan": payment_plan
,"created": created.getTime()
,"updated": updated.getTime()
,"avatar": this.avatar})
.zadd("u:users", 0, ID)
.sadd("u:emails", this.email)
.set("u:"+ ID + ":stats", 0)
.set("em:" + this.email, ID)
.exec();
this.postInsert();
if (callback != null)
callback(null, this);
}
this.save = function(callback) {
// new user
if (ID == -1) {
var u = this;
Common.client.watch("u:" + this.username);
Common.client.exists("u:" + this.username, function(error, exists) {
// This username already exists
if (exists == 1) {
Common.client.unwatch();
if (callback != null)
callback({code: 100, message: "This username already exists"});
}
else {
Common.client.watch("em:" + u.email);
Common.client.get("em:" + u.email, function(err, emailExists) {
if (emailExists != null) {
Common.client.unwatch();
if (callback != null)
callback({code: 101, message: "This email is already in use"});
}
else {
Common.client.incr("u:nextID", function(error, id) {
if (error) callback(error);
else {
ID = id;
u.insert(callback);
}
});
}
});
}
});
}
// existing user
else {
var u = this;
Common.client.get("em:" + this.email, function(err, emailExists) {
if (emailExists != ID && emailExists) {
if (callback != null) {
callback({code: 101, message: "This email is already in use " + ID + " " + emailExists});
}
}
else {
u.update(callback);
}
});
}
}
输出几乎总是:
1 email is locked test@test.com
2 email is locked test@test.com
3 email is locked test@test.com
4 email is locked test@test.com
5 email is locked test@test.com
6 email is locked test@test.com
7 email is locked test@test.com
8 email is locked test@test.com
9 email is locked test@test.com
10 email is locked test@test.com
是我做错了什么,还是redis无法处理那么多并发性。
此外,这也是常见问题的定义:
var Common = {
client: redis.createClient(),
...
};
对!!当然,经过一夜的休息,我在淋浴时想到了解决办法
问题是我在整个应用程序中使用了一个redis线程,所有连接都在该线程上注册了手表。当然,它并不表示密钥被其他客户端修改,因为没有其他客户端。是的!当然,经过一夜的休息,我在淋浴时想到了解决办法
问题是我在整个应用程序中使用了一个redis线程,所有连接都在该线程上注册了手表。当然,这并不表示密钥被其他客户端修改,因为没有其他客户端。我知道此线程已经运行了8个月,但无论如何,我的想法仍然可以帮助某些人。有一个问题我仍然不能理解,我甚至开始了我自己的线程专用于这个问题,我指的是你的。我现在使用“每个事务的连接”方法,这意味着如果我需要使用WATCH-MULTI-EXEC进行事务,我将创建新的连接。在其他情况下,对于原子操作,我使用在应用程序启动期间创建的连接。不确定这种方法是否有效,因为创建一个新连接意味着创建+授权,这会产生延迟,但它是有效的。我知道这个线程已经运行了8个月,但无论如何,我的想法仍然可以帮助某些人。有一个问题我仍然不能理解,我甚至开始了我自己的线程专用于这个问题,我指的是你的。我现在使用“每个事务的连接”方法,这意味着如果我需要使用WATCH-MULTI-EXEC进行事务,我将创建新的连接。在其他情况下,对于原子操作,我使用在应用程序启动期间创建的连接。不确定这种方法是否有效,因为创建一个新连接意味着创建+授权,这会产生延迟,但它是有效的。我也使用了这种方法。单例连接上99%的操作。但是对于一些需要监视的操作,我创建了一个新实例。我也使用了这个方法。单例连接上99%的操作。但是对于一些需要监视的操作,我创建了一个新实例。