redis bitmap 入门

1.简介

bigmap是通过类似map结构存放0或1(bit 位)作为值,一般用来统计状态.如:日活,是否浏览过某个东西


2.setbit

redis 127.0.0.1:6379> help setbit


  SETBIT key offset value

  summary: Sets or clears the bit at offset in the string value stored at key

  since: 2.2.0

  group: string


例子:

redis 127.0.0.1:6379> setbit aaa:001 10001 1 #返回操作之前的数值

(integer) 0

redis 127.0.0.1:6379> setbit aaa:001 10002 2 #如果值不是0或1就报错

(error) ERR bit is not an integer or out of range

redis 127.0.0.1:6379> setbit aaa:001 10002 0

(integer) 0

redis 127.0.0.1:6379> setbit aaa:001 10003 1

(integer) 0



3.getbit

redis 127.0.0.1:6379> help getbit


  GETBIT key offset

  summary: Returns the bit value at offset in the string value stored at key

  since: 2.2.0

  group: string


例子:

redis 127.0.0.1:6379> getbit aaa:001 10001 

(integer) 1



4.bitcount

redis 127.0.0.1:6379> help bitcount


  BITCOUNT key [start] [end]

  summary: Count set bits in a string

  since: 2.6.0

  group: string



redis 127.0.0.1:6379> bitcount aaa:001 0 -1

(integer) 2

redis 127.0.0.1:6379> bitcount aaa:001

(integer) 2





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值