Redis On Windows - Part Two

Recap

In the Redis On Windows – Part One article we saw what Redis is all about and why it is recommended in both Over-the-Cloud and On-Premise solutions. For a quick glance at the details, you may want to refer to the Part One article,

In this article, we’ll have a look at Installation Options and Configurations for Redis on Windows. Redis is an in-memory database that persists on disk and open source.

Installation

MS Open Tech has been publishing the Redis Releases at this Github URL. As such there are multiple releases published by them at this URL but with disclaimers. Out of those, Redis 2.8.21x build being the stable one as of this date, I preferred to install the same on my Cache Servers. As I mentioned earlier, you can install Redis Service either directly by running the MSI using the Installer’s UI or from the command line. Let’s have a look at different options available for the installation.

Installation using MSI.

  1. Download & Run Redis 2.8.21x (stable release as of date) MSI from the above mentioned GithubURL.

  2. Select default options to perform installation and while setting port in the below window:

    You may prefer to have “Add an exception to the Windows Firewall” selected.

    setup

  3. Complete the Installation process.The installation process itself sets Redis Windows Service in “Running” state.

  4. Open Service Control Manager (Control Panel, System and Security, Administrative Tools, then Services) a.k.a. Services.msc and make sure that Redis Service is running.

Installation using MSI (Using Command Line)

The following are the ways to install Redis Service using MSI package from command line,

Default Installation

It defaults the Windows Port to 6379 with Windows Firewall Exception set to ON. The command is,

msiexec /i Redis-Windows-64.msi

Setting Port & Turning OFF Firewall Exception

msiexec /i Redis-Windows-x64.msi PORT=1234 ADD_FIREWALL_RULE=""

Setting Port & Turning ON Firewall Exception

msiexec /i Redis-Windows-x64.msi PORT=1234 ADD_FIREWALL_RULE=1

Installation without User Interface

To install Redis Service silently with all default options i.e. default Windows Port 6379 with Windows Firewall Exception ON, the Command Prompt needs to be run using elevated privileges like Administrative Mode and the following command is executed,

msiexec /quiet /i Redis-Windows-x64.msi

Note:

To uninstall Redis Service from Command Line “msiexec /x Redis-Windows-64.msi” command can be used.
 
Because MS Open Tech provides MSI Installable, we really don’t require to register Redis Service i.e. redis-server.exe explicitly to the Service Control Manager. However, it is possible to directly register the Redis Service in Service Control Manager without help of the installer.We’ll use the latest version of Redis(which is not ready to production yet) for that purpose since the installer is not available for it.The latest version can be availed from Current Redis Version URL.

It can be achieved from the Command Prompt and the Command Line arguments would require an elevated user context in order to connect to the Service Control Manager and hence the Command Prompt needs to be run in Administrative Mode.

The following steps depict the way to register the Redis Service to the Service Control Manager:
  1. Run Command Prompt in elevated user context such as Administrator.

  2. Change folder to where latest Redis zip folder has been extracted.

  3. Execute the following command at the command prompt:
    redis-server.exe --service-install redis.windows-service.conf

  4. Open Service Control Manager and find the Service Name as Redis appearing in the list of services. Right click it and start the service.

Likewise various arguments have been introduced for Redis Service to start, stop, rename and uninstall the Service. Their usage is as follows,

  • redis-server.exe –service-start
  • redis-server.exe –service-stop
  • redis-server.exe –service-name<name>
    (This one is to change the default name of the service)
  • redis-server.exe –service-uninstall

Checking Redis Connectivity

To ensure that Redis Service is working properly, connect the Redis instance using redis-cli.exe utility which is present right under the Redis folder. For that purpose perform the following steps:

  1. Open Command Prompt
  2. Change folder to Installed Redis Folder location (by default C:\Program Files\Redis)
  3. Enter command redis-cli.exe
  4. A command prompt will change to “127.0.0.1:6379>“
  5. Now perform the following commands:

    a. SET sampleKey sampleValue

     The key called sampleKey will be set with its value = sampleValue

    b. KEYS *

    It will list all the keys set so far. In our case it will list “sampleKey”.

    c. GET sampleKey

    It will return its corresponding value i.e. sampleValue.

    d. DEL sampleKey

    This command will delete key & value for sampleKey key from Redis Data Store.

    e. FLUSHALL

    This command will delete all the keys & their corresponding values from Redis Data Store.

Note: For all commands please refer to Redis IO Commands.

Once this has worked, it indicates that Redis Server has got installed properly.

Now we can configure the behavior of the service using “redis.windows-service.conf” located at the installed folder path.

Configuration:

As mentioned earlier, although the Redis configuration file is quite self-explanatory for each and every configuration parameter and Redis Service can be used without even modifying any parameter values, I would like to mention a few parameters which I preferred to modify on purpose:

  1. port <port number>

    One might prefer to use different port than the default one that Redis tends to use.

  2. dbfilename dump.rdb

    One might find dump.rdb name very generic and might prefer some relevant name for the Redis Data Store

  3. save <seconds> <changes>

    This setting triggers Redis Service to store the in-memory data to its configured Persistent Data Store (dbfilename).
    After the configured <seconds> if Redis data in memory has got changed for the number of times mentioned in <changes> then only it saves data to the Persistent Data Store. By default, these values are high and the data would live in memory for 15 minutes if less than 10 values are getting changed in every 5 minutes.

  4. slaveof<masterip> <masterport>

    This parameter helps attach a slave to a master in Multi-Server Redis scenario. Master IP Address and Master Redis Port needs to be set in here. Enabling this setting enables Data Replication from Master to Slave and ensures that the Master and Slave Data Stores are in sync.

  5. logfile <filename>

    To mention the log file name to maintain Redis Server log.

Note: After changing any configuration for it to take an effect, the service needs to be restarted from Service Control Manager.

Summary

In this part we had a look at,

  • Installing Redis Service using MSI with Installer’s UI or with Command Line.
  • Directly registering the Redis Service to Service Control Manager using the Command Line options provided by Redis in elevated user context.
  • Checking the connectivity with Redis Service using redis-cli.exe utility.
  • Certain Configuration Settings.

In the next chapter we’ll learn about the Redis Clients and how to access Redis Service using a Redis Client to cache values of primitive as well as User-defined data-types.

Read more articles on Redis:

Up Next
    Ebook Download
    View all
    Learn
    View all