Home > Backend Development > PHP Tutorial > Record user gender using redis bit operations

Record user gender using redis bit operations

WBOY
Release: 2023-03-01 18:22:02
Original
1650 people have browsed it

Reading and seeing content related to redis bit operations, there is an example in the book: For example, each user on the website has an auto-incremented ID, and a string type key is used to record the user's gender..., I want to know the specific operation of this recording method, or what the idea is. I know that it must be distinguished by bits 1 and 0, but how is it recorded?

Reply content:

Reading and seeing content related to redis bit operations, there is an example in the book: For example, each user on the website has an auto-incremented ID, and a string type key is used to record the user's gender..., I want to know the specific operation of this recording method, or what the idea is. I know that it must be distinguished by bits 1 and 0, but how is it recorded?

setbit key offset, where offset is replaced by userid, if the user with ID 1 is male, just setbit key 1 1, if it is female, just setbit key 1 0, to get the gender of ID 1, just getbit key 1

<code class="php">$redis->mSet($userId,['age'=>18, 'gender'=>0]);//小明
$redis->mSet($userId2,['age'=>16, 'gender'=>1]);//小红

$user = $redis->mGet($userId);
echo $user['gender'];//
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template