<> demand

There is an interesting demand recently , Establishment of user's family account system , premise ( Small program development , Front end can't detect applet exit completely ), Member accounts in the family A Before switching login, you need to judge another account B Last use time of No , If the account number A stay
Logged in within two hours , I will check the account number A There's a hint , Do you want to squeeze out accounts B, Simultaneous account number B When calling the request again , You'll also receive the account number you've been given A Crowd out the notice , Exit to the authorization login interface .

<> terms of settlement

Because of the above requirements, the solution is to use Redis,Redis Set a valid time for each account in (2 hour ) Of token value , By judging each user token Does the value exist , To judge all kinds of reminders when the account is squeezed out . But there's a problem , Requirements token What is the failure time 2 hour , Last account within two hours
Login will remind ( The last update of the previous account needs to be judged token time ), So the front end calls each request , The back end needs to be updated redis Expiration time of .

* Node.js Quoted in Redis var redis = require('redis'), PORT = 6389,// Port number HOST =
'127.0.0.1', // The server IP PWD = '88888888888888', // password OPTS = {},// Set item rclient =
redis.createClient(RDS_PORT,RDS_HOST,RDS_OPTS);
rclient.auth(RDS_PWD,function(){ console.log('redis Certified '); }); //redis database
rclient.set('token','kaola');// assignment
* Redis set up key Expiration time of rclient.expire('token',60);// set up 60 Seconds automatically expired
*
Redis to update key Expiration time of

For a person who already has time to live key implement EXPIRE command , The new specified lifetime will replace the old lifetime
rclient.expire('token',60);// to update token Expiration time 60 second
attach : The small requirements mentioned above are the way to think of at present , If there is a better way to realize it, we can discuss it together .

Technology