Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save c80609a/6d49bd7572057041a07e9c2dfd7d90e6 to your computer and use it in GitHub Desktop.
Save c80609a/6d49bd7572057041a07e9c2dfd7d90e6 to your computer and use it in GitHub Desktop.
redis is amazing <3
# 100mil 'entities'
# need to be able to check from a random subset if 'something' is TRUE or FALSE
# set booleans in a redis bitmap where the ID for the entities are the offset
$ redis-cli
> SETBIT mybitmap 100000000 1 # 8ms
> SETBIT mybitmap 99999999 1 # 2ms
> SETBIT mybitmap 10000000 1 # 2ms, etc
> SETBIT mybitmap 1000000 1
> SETBIT mybitmap 100000 1
> SETBIT mybitmap 10000 1
> SETBIT mybitmap 1000 1
> SETBIT mybitmap 100 1
> SETBIT mybitmap 10 1
> SETBIT mybitmap 1 1
# memory used for this bitmap 16MB
> GETBIT mybitmap 99999999 # 2ms
> GETBIT mybitmap 99988889 # 2ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment