Using PHP Resque with Redis Sentinel
We’re using Redis Sentinel to provide high availability for our Redis deployment. One of the struggles we had as we made this transition was finding a way to get php-resque to connect to Redis Sentinel as well.
By default, php-resque connects to the default port on the local server. If you need to point is somewhere else their documentation provides a single example for setting the server to something else:
The quick solution to fix this is would be to use the Credis library to determine what the master is and set the server to that. That doesn’t allow for us to read from the slaves which is a huge benefit to using Sentinel. After digging through the source code, I found that you can pass a function instead of a string to the setBackend
function so it can setup the connection. Credis provides a Credis_Sentinel class that allows for a connection to the cluster but is smart enough to split reads and writes and has the same methods so they’re interchangeable. Below is how this works.
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows