美文网首页
Redis Bitmaps

Redis Bitmaps

作者: nzdxwl | 来源:发表于2019-12-09 00:05 被阅读0次

Redis位图:
位图并不是一种实际的数据类型,而是在字符串数据类型上定义的按位操作集合(对普通的字符串键也可以进行位图操作)。由于字符数据是二进制安全的数据块并且最大长度可以达到512MB,它们适用于2的32次方个不同的位。

位操作可以分成两种:一种是常量时间单个位操作,例如单个位赋值或取值,一种是对多个位组成的位组进行操作,例如计算某个范围中有赋值位的数量等。

位图最大的优势之一就是使用它存储信息时可极大节约存储空间。

Bitmaps are not an actual data type, but a set of bit-oriented operations defined on the String type. Since strings are binary safe blobs and their maximum length is 512 MB, they are suitable to set up to 232 different bits.

Bit operations are divided into two groups: constant-time single bit operations, like setting a bit to 1 or 0, or getting its value, and operations on groups of bits, for example counting the number of set bits in a given range of bits (e.g., population counting).

One of the biggest advantages of bitmaps is that they often provide extreme space savings when storing information. For example in a system where different users are represented by incremental user IDs, it is possible to remember a single bit information (for example, knowing whether a user wants to receive a newsletter) of 4 billion of users using just 512 MB of memory.

Bits are set and retrieved using the SETBIT and GETBIT commands

使用bitpos key bit_value(0或者1)来获取最近的0/1值位的位置
使用bitcount key [start end] 来获取指定的键中位值=1的个数,或者指定键的位范围中
还有bitop operation dest_key key [key1 .. ] 使用指定键值对目标键值按位操作,支持与、或、异或和非操作

位图的缺点:
只支持连续自然数值范围,非连续自然数值范围时需要额外信息来协助使用。

相关文章

  • Redis Bitmaps

    Redis位图:位图并不是一种实际的数据类型,而是在字符串数据类型上定义的按位操作集合(对普通的字符串键也可以进行...

  • redis的bitmaps的应用-网站签到的设计和网站的数据统计

    在使用redis设计签到系统,我们可以使用集合和bitmaps两种数据结构。这边我们来说明一下bitmaps。 1...

  • 2.解决缓存穿透,布隆过滤器

    String 类型在redis内部是按照二进制存储的(bitmaps) setbit key offset val...

  • bitmaps.md

    Dirty Bitmaps and Incremental Backup Dirty Bitmaps are ob...

  • Redis数据结构 - Bitmaps

    Bitmaps不是实际意义上的数据类型,而是定义在字符串类型上的一组面向比特位的操作。由于字符串是二进制安全blo...

  • redis BitMaps数据结构

    1. 数据结构模型 现代计算机用二进制(位)作为信息的基础单位,1个字节等于8位,例如“big”字符串是由3个字节...

  • Redis数据类型之Bitmaps

    本文介绍redis的新数据类型之一:bitmaps。它在当今的互联网环境当中有很多的应用场景,比如常见的签到、点赞...

  • bitmaps

    Roaring bitmaps 说到Roaring bitmaps,就必须先从bitmap说起。Bitmap是一种...

  • Bitmaps

    Bitmaps 并非Redis的一个数据结构,其根本还是字符串,只不过可以直接对字符串的位进行操作 设置值: se...

  • Loading Large Bitmaps Efficientl

    原文地址:Loading Large Bitmaps Efficiently in AndroidLoading ...

网友评论

      本文标题:Redis Bitmaps

      本文链接:https://www.haomeiwen.com/subject/tlemgctx.html