I am using redis's 1 master & 1 slave.
I also want to use both under load balancer.So that I can make use of both redis server at once.
Also I want to add slave as master's fail over. So can I do it?
Instead of using the built-in redis sync, what about handling this in the code of your custom state service?
So with two or more servers under load balancing, they would each have a list of the other servers and after writing to their local Redis instance they would just write the same entry to the rest?
Assuming that works, then it should just be a matter of handling synchronization of an instance when bringing a server back online. Could you force this when your service restarts? Make the local version sync to another instance? Or just get all the entries with dates later than the latest locally?
I would not recommend it. Redis is currently a master-slave replication mechanism and you would need to partition writes vs. reads. A load balancer will not do this for you without significant work. You will need to partition reads vs. writes in your app, or write an intermediary layer. Once you've done this you can put multiple slaves behind a load balancer and point writes to a single master.
Redis is fast enough that rarely will you see a significant delay in replication. Especially if you run the master configured to not write locally, and run one or more slaves not behind the load balancer that handle persistence.
As far as handling a down master, you could write/use a heartbeat style monitor on one or more slaves that monitor for a dead master and take over. You could still use a load balancer for some of this. For example, use a virtual IP on the LB and set the appointed secondary as a lower weight or whatever your chosen LB's term is). Then configure this server to be a slave to the master - but not in the read pool. Have it listen a non-standard port that the LB does not route to. When it detects the master has failed the process you use then reconfigures it to use the proper port and issues a SLAVE OF NOONE command.
I would also prefer to see that monitor process then tell the load balancer to not use the master at all. That way if it comes back online before you are ready you can slave it to the current master and then migrate back to it once it has synchronized with the backup master.
Ultimately how much value is in the work depends on how strict your true requirements are. Either way, if you are truly in need of not losing a single write, you will want to code your writer such that if it can not connect it queues those writes to disk and logs or alerts someone.
I have never tried it, but the main issue is that with replication, even synchronous replication, redis only allows for a master slave relationship and not a master/master relationship.
The consequences of this is that if you write to the slave, those writes won't be available on the master.