Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of prohibiting Multi-end Login based on Redis unordered set

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is about how to implement the function of prohibiting multi-side login based on Redis unordered collection. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Preface

A collection type can store up to 2 ^ 32-1 strings

Collection types are implemented inside redis using a hash table (hash table) with empty values, so the time complexity of adding or deleting elements in the collection is O (1).

The collection has element uniqueness.

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)

If ($redis- > sIsmember) {/ / true} else {/ / false}

B judgment

If ($redis- > sIsmember ('baked setbacks grammatical user ID)) {/ / true} else {/ / false}

The method used

Sadd key_set value setting value to set

The sismember key_set value judgment value is stored in the key_set.

Srem key_set value removes the specified value

Smembers key_set gets all the value

Thank you for reading! This is the end of this article on "the method of prohibiting multiple logins based on Redis unordered sets". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report