watch mysql binlog event, update redis cache.
why use binlog2cache?
When cache in redis and data in mysql are inconsistent, the case cause dirty data. so we can update cache active by binlog2cache.
- dep
pip install -r requirements.txt
-
modify config.py
-
python binlog2cache.py
-
redis-cli monitor
mysql data
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| pid | int(11) | YES | | NULL | |
| cid | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
redis cache data
hash
key --> db:table:id:pid
field --> pid
value --> xxx
field --> cid
value --> xxx
open binlog and set binlog-format
[mysqld]
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 1000M
binlog-format = row