ThinkingCog

Articles written by Parakh Singhal

Running Redis as a Service in 32 bit Windows

Key Takeaway:

Learning a lot of NoSQL data-stores is easy in part because all you have to do in order to run the server, is to click on an executable file and it starts listening on a local IP address and port. Redis works the same way. But in order to run Redis in production environment, one cannot rely on a console application listening on a port. After all, there’s always a risk of someone closing the console application and shutting down the entire cache.

To remediate this, we run such products as services. Redis is no exception and in this article we will learn how to run Redis as a Windows service.

Read on:

In my last article I showed how to compile and run Redis in a 32 bit Windows environment. In this article, I am going to use the same build to run it as a Windows service.

NOTE: If you have a 64 bit processor computer, you can directly go to this link and download the binaries, in ready to use condition.

NOTE: It is always preferable to run Redis on non-default port, as that gives us the option of running an ad-hoc instance of Redis server for quick experimentation and learning. In this exercise we are going to run Redis as a service in 32 bit Windows environment and provide the runtime configuration via a configuration file.

1. Navigate to the folder with a sample configuration file. In the source code that folder will be

redis-3.0->msvs->setups->documentation->redis.windows.conf.

2. Locate the line that signifies the port on which the Redis will listen for connections. This is found in “General” category. To search, use the word “port” and change the port number to something that is available on your machine. For this exercise, change it to 6377.

Redis configuration

 

 

 

 

 

 

 

 

 

 

 

3. Copy the file in the same folder as redis-server.exe. If you compiled the code that folder will be located at the following location: redis-3.0->msvs->Win32(*mine is 32 bit environment)->Release(* compile configuration). For more information on how compile Redis source code for 32 bit Windows environment, refer to my last post.

4. Open a command prompt and navigate to the location where you are storing the Redis executable named redis-server.exe and execute the following commands:

a. C:/Redis-3.0>Redis-server - -service-install redis.windows.conf  - -service-name “Redis Server”

b. C:/Redis-3.0>net start “Redis Server”

c. C:/Redis-3.0>Redis-cli –h 127.0.0.1 –p 6377

Test Redis installation as a service

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5. If the service installation was successful and it started successfully, then you will be able to ping the server and receive a response back.

6. Just in case you decide to uninstall the service, issue the following commands:

a. C:/Redis-3.0\msvs\Win32\Release>net stop “Redis Server”

b. C:/Redis-3.0\msvs\Win32\Release>sc delete “Redis Server”

Stop and uninstall Redis service

 

 

 

 

 

 

 

 

 

 

Now you can go ahead and practice with Redis command line interface by connecting to this service.

Running Redis in 32 bit Windows

Key Takeaway:

Redis started its life in Linux environment and to this date, it is officially supported only in Linux environment. However, the good folks at Microsoft had started a new division with the sole purpose of porting such useful products to Windows environment and let developers use them with confidence and with the support of Microsoft behind them. Even though that division has now merged back into Microsoft, engineers at Microsoft continue to make contributions to ported projects.

With the 64 bit architecture becoming the de-facto standard in commodity computers, open source contributors and organizations around the world have started to focus on releasing binaries for 64 bit architectures. That leaves people like me who are living perfectly fine life with their old trusty computers having 32 bit processors powering them. The silver lining in this scenario, is that if you have access to the source code of a product, then you can compile it for 32 bit architecture and then use it.

This article shows how to download Redis source code, compile it using Visual Studio for a 32 bit architecture and then run it in a Windows environment.

Read on:

If you are a .Net developer, chances are that you have for majority of your professional life, written code on Windows platform, for Windows platform. On top of that if you have an old computer powered by a 32 bit processor, then you are striving to find ways to learn the new and up-coming technologies, such as NoSQL databases – MongoDB, Redis etc. which primarily have been released for 64 bit architectures.

I have been working with Redis since the past couple of months now and started learning Redis on my personal laptop which at the time of writing this article is 8 years young. This sometimes leaves me in a bit of a lurch as the newer projects and products are mainly focusing on releasing for 64 bit architectures. Well, all is not lost if you are willing to put up a little fight and compile the source code yourself, if it is available.

Thankfully Microsoft recognized that .Net developers should not get left behind when it comes to awesome products like Redis, just because they are not available to be run in the Windows environment, and hence they created a dedicated entity, Microsoft Open Tech Group devoted to porting these technologies in the Windows environment, and further the collaboration with the open source community. Redis is one of the projects that the group is handling at the moment.

Alright, so let’s run Redis on Windows in 32 bit architecture. Pre-requisite for accomplishing this is the newest version of Visual Studio 2013 with update 5, as without update 5, the process might not work successfully. If you do not have a paid version of Visual Studio, Community Version which is available for free here will also work.

1. Head over to Microsoft Open Tech Group’s Redis GitHub page for version 3.0 and download the source code available as a zip file.

2. Unzip the code in a folder in C drive. Make sure that the folder name in which the source code is housed bears a name with no space or special character.

3. Open the solution located in the msvs folder in Visual Studio.

4. Open the solution’s properties and go to the configuration manager and change the “Active solution configuration” to Release and “Active solution platform” to x86.

clip_image002

 

 

 

 

 

 

 

 

 

 

 

5. Now build the solution. Note there will be a few warnings that’ll come up, but ignore them.

6. Once the build completes, you will notice that there will be a new folder named “Win32” that would have gotten created. Inside this folder will be another folder “Release”. Release folder contains the final build and the executable files that we can use to run and learn Redis.

7. Locate the file “redis-server.exe” and execute it. It should come up looking something like shown here. This is the Redis server which by default listens on IP address 127.0.0.1 and port 6379.

clip_image004

 

 

 

 

 

 

 

 

 

 

8. Locate the file “redis-cli” and execute it. It should come up looking something like shown here. This is Redis command line interface and by default it sends commands on the address and port of 127.0.0.1 and 6379 respectively.

clip_image006

 

 

 

 

 

 

 

 

 

 

Lo and behold, we have Redis running in 32 bit Windows environment. Thanks to the brilliant folks at Microsoft for porting this valuable piece of technology to Windows environment.