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?
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>