A Redis module that allows forwarding write commands from slave(s) to master.
Scaling read-intensive Lua-based Redis app with horizontal scaling of slaves. Occasional writes are proxied to master.
HiredisProxy is a simple Redis module based on Hiredis, a minimalistic C Redis client. It only runs on slaves and automatically connects to the master by pulling connection information from the current Redis state.
step | slave | master |
---|---|---|
Start two servers | $ redis-server --port 6380 --dir . --loadmodule hiredisproxy.so |
$ redis-server --port 6379 |
Connect to both Redis servers | $ redis-cli -p 6380 |
$ redis-cli -p 6379 |
Monitor master to see what's happening | 127.0.0.1:6379> monitor |
|
Activate slave role | 127.0.0.1:6380> slaveof 127.0.0.1 6379 |
1479175823.971904 [0 127.0.0.1:62543] "PING" |
Proxy a command to master | 127.0.0.1:6380> hiredis.proxy set more lemmings |
1479175834.943794 [0 127.0.0.1:62544] "set" "more" "lemmings" |
Access it locally (from replication) | 127.0.0.1:6380> get more lemmings |
- Clone the redis modules sdk
git clone https://github.com/RedisLabs/RedisModulesSDK.git
- Clone Hiredis into it
cd RedisModulesSDK
git clone https://github.com/redis/hiredis.git
- Clone HiredisProxy into it
git clone https://github.com/synku/HiredisProxy
- Make
cd HiredisProxy
make
- This is not yet tested enough to be considered production ready, please help!
- Everything is synchronous so the proxying is costly timing-wise
- How else would you use this?
This project was born from our ever-growing scaling efforts at [ClarityAd] (https://www.clarityad.com). We're hiring! Hit me up at @j_rom_