I really love both redis and mysql, and use them both extensively. I am interested in purging certain keys that I no longer need from my redis instance because, well, memory is expensive. I'd like to park it on disk and leave it there forever. I'm not very particular about how, but I'm exploring housing it in mysql. For most redis data types, this is cake. It's either a string, or something or something json encoding can handle easily. My problem is bitmaps which are binary representations of data.
Here is my naive psydo code/python approach:
#create an arbitrary bitmap with every third bit ticked to 1
for i in range(100):
rediscon.setbit('thekey',i*3, 1)
#get the value as a string
thevalue = rediscon.get('thekey')#is get appropriate for a bitmap?
#this looks something like "@ \b\x02\x00\x80 "
#do the insert into mysql
mysql.query("insert into table (key, value) VALUES ('thekey', "+MySQLdb.escape_string(thevalue)+")")
#do a sanity check, restore the key back to redis
#get the value from mysql and put it back in redis with a new key
val = MySQLdb.query("select value from table where key='thekey'")
rediscon.set('thekey_new', val)
print rediscon.bitcount('thekey')#this prints correctly as 100
print rediscon.bitcount('thekey_new')#this is wrong, it prints a number much less than 100
The mysql engine type is myisam, which I don't think matters. And I've tried BLOB and LONGTEXT for the column type for values
. Is doing a get
on a bit map what I want to do? How do I do an insert in mysql with binary data?
How do I do this? I want to be able to put this bit map in mysql, and then have the ability to restore it later. Thanks!