Saturday 11 April 2015

Redis Bitmaps

Bitmaps are used to support Bit oriented operations. Suppose if you want to maintain attendence of sudents (ids 1 to 100), 100 bits are enough to save today attendence.

SETBIT key offset value Sets or clears the bit at offset in the string value stored at key. Example setbit today 8 1 Above statement sets 8th bit of key “today” to 1. BITCOUNT key start end Count number of bits set in given bitmap key. Example bitcount today 1 100 Above statement returns 7, means 7 students attended for today class.
k@hk-Inspiron-N5010:~$ redis-cli 
127.0.0.1:6379> setbit today 8 1 
(integer) 0 
127.0.0.1:6379> setbit today 10 1 
(integer) 0 
127.0.0.1:6379> setbit today 13 1 
(integer) 0 
127.0.0.1:6379> setbit today 17 1 
(integer) 0 
127.0.0.1:6379> setbit today 23 1 
(integer) 0 
127.0.0.1:6379> setbit today 29 1 
(integer) 0 
127.0.0.1:6379> setbit today 31 1 
(integer) 0 
127.0.0.1:6379> bitcount today 1 100 
(integer) 7 
 
SETBIT key offset value
Sets or clears the bit at offset in the string value stored at key.

Example
setbit today 8 1
Above statement sets 8th bit of key “today” to 1.

BITCOUNT key start end
Count number of bits set in given bitmap key.

Example
bitcount today 1 100
Above statement returns 7, means 7 students attended for today class.


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment