Answer the question
In order to leave comments, you need to log in
How to solve problem with redis?
The bottom line is this: the 1st user creates a game room (game_id) and connects to it, immediately entered into redis
client.rpush("game_id:"+game_id, username);
client.rpush("status:enable", array); //открыть комнату для подключения
. client.rpush("game_id:"+game_id, username);
. client.lrange("game_id:"+game_id, "0", "-1", function(error, result){
for(var i=0; i<result.length;i++{
//Получаем имена
//Успешно отправляем клиенту
}
}
if(result.length==8){
client.lrem("status:enable", "0", array_id); //удалить комнату из "доступных к подключению".
...//основные действия
}
. Answer the question
In order to leave comments, you need to log in
You don't understand the sequence of client.rpush and client.lrange
If your asynchronous requests are not executed sequentially, it is quite likely that lrange is executed first, and then only rpush.
User 8 came, checked lrange == 7, does not close the room. Next, rpush is executed.
Then the 9th user comes and then lrange becomes 8 and the room closes
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question