How to prevent users from logging in to multiple applications by Redis
Application background
The names of multiple applications are assumed to be An and B, which prohibit users from logging in from A / B at the same time.
Realization idea
Set two unordered sets a_set, b_set
A / b executes when logging in
$redis- > sAdd ('ajar setter sRem); / A log in to $redis- > sRem (' bouncy setter dagger camera UserID); / / kick Blockrediss-> sAdd ('bouncy setter requlibility UserID); / B Log in to $redis- > sRem (' aholysetter reflexive UserID); / / kick A
Before api acquires data, determine whether the id of this end is online (the api of the two sides of the AB is separate)
A judgment:
If ($redis- > sIsmember) {/ / true} else {/ / false}
B judgment
If ($redis- > sIsmember ('baked setbacks grammatical user ID)) {/ / true} else {/ / false}
The methods used are:
When the sadd key_set value setting value is set to the sismember key_set value judgment value in set, there is a srem key_set value in key_set to remove the specified value smembers key_set to get all value.
The above are the details of the method of prohibiting multi-side login based on Redis unordered collection, please pay more attention to other related articles!