Skip to content

Instantly share code, notes, and snippets.

@tortuetorche
Last active April 12, 2020 23:06
Show Gist options
  • Save tortuetorche/9830345 to your computer and use it in GitHub Desktop.
Save tortuetorche/9830345 to your computer and use it in GitHub Desktop.
Redis for Windows as a Memcache successor for PHP applications and as a queue driver for Laravel

Install Redis as a service on Windows

Installation instructions

  1. Download and extract the last Redis version (2.8.4)
  2. Copy all extracted binaries to c:\redis\bin
  3. Create another folder at c:\redis\inst1
  4. Download and extract the RedisWatcher binaries from the 2.4 branch
  5. Run InstallWatcher.msi with administrator rights. This should create a Windows service called Redis watcher.
  6. Open up the Windows Services console and start the Redis watcher service.
  7. (optional) RedisWatcher should have installed to C:\Program Files (x86)\RedisWatcher. There you'll find a config file called watcher.conf, which you can edit to set up additional instances, use different paths than I specified in steps 2 & 3, etc. You will not need to restart the service for changes to take effect.

Source: http://stackoverflow.com/a/20200022 and http://msopentech.com/blog/2014/03/24/updates-released-redis-windows

Add C:\redis\bin to Path Environment Variable

Computer->Properties->Advanced->Env Variables->Path : ;C:\redis\bin;

Check if Redis is working

$ redis-cli ping
PONG

Running redis-cli followed by a command name and its arguments will send this command to the Redis instance running on localhost at port 6379. You can change the host and port used by redis-cli, just try the --help option to check the usage information.

Another interesting way to run redis-cli is without arguments: the program will start into an interactive mode where you can type different commands:

$ redis-cli                                                                
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379> set mykey somevalue
OK
redis 127.0.0.1:6379> get mykey
"somevalue"

Memcache replacement for PHP

Read this article to config Redis like Memcache.

Use this PHP class which mimic Memcache class API with Redis and PhpRedis extension: MemcacheRedis

TODO:

  1. Add close() method and a create dummy setCompressThreshold() method
  2. Tweak MemcacheRedis class to use Predis instead of PhpRedis. Because it's more portable (Windows support without compiled extension).

Redis queue for Laravel on Windows

Create a Windows Service with NSSM

  1. Download the last pre-release version of Nssm
  2. Extract the file win64\nssm.exe in C:\Program Files\nssm.
  3. Add ;C:\Program Files\nssm; to the Path environment variable.
  4. In a console, run: nssm install my_app_name_queue
  • In the Application tab: select for the Path field C:\my_application_root_path\start_queue.bat.
  • In the Dependencies tab: Add RedisWatcherSvc service name.

Or create a Windows Service with old Microsoft tools

  1. http://serverfault.com/a/469205 or http://wiki.scn.sap.com/wiki/display/Basis/How+To+Install+a+Batch+file+as+Windows+Service
rem Copy this file in your Laravel application root path
C:
cd C:\my_application_root_path
php artisan queue:listen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment