APPENDIX · P16 · REDIS · ANALYTICS · FOR SLIDE 13
← Back to Slide 13
P16. HyperLogLog and Bitmaps
# уникальные за день и дни входа
DEL lesson03:dau:2026-09-29 lesson03:dau:2026-09-30 lesson03:login:1042:2026-09
PFADD lesson03:dau:2026-09-29 1042 2001 3003
PFADD lesson03:dau:2026-09-30 1042 2001 1042 4004
PFCOUNT lesson03:dau:2026-09-30
PFCOUNT lesson03:dau:2026-09-29 lesson03:dau:2026-09-30
SETBIT lesson03:login:1042:2026-09 28 1
SETBIT lesson03:login:1042:2026-09 29 1
BITCOUNT lesson03:login:1042:2026-09
GETBIT lesson03:login:1042:2026-09 27
What the result should be
PFADD: (integer) 1, then 1
PFCOUNT for one day: approximately 3
PFCOUNT for two days: approximately 4
Estimated; not a guarantee of an exact number.
SETBIT: (integer) 0, then 0
BITCOUNT: (integer) 2
GETBIT for September 28: (integer) 0
HyperLogLog
Association
Bitmap
Approximate number of unique entries: an error margin of about 0.81%, no more than 12 KB per key. It does not store a list of IDs.
PFCOUNT, when used with multiple keys, estimates the number of unique values for the period without summing the daily counts; the result is an approximation.
30/31 bits require 4 bytes of data per player; the size of the Redis key and overhead are additional.
Precise data and metrics belong in PostgreSQL. Approximate analytics and activity counters are a good fit for Redis or an analytical DBMS.