Getting Started with Redis and setup it on windows

Muhammad Zain Tariq
7 min readDec 28, 2020

A beginner guide about Redis and its setup on windows

In this Blog, You will Learn

  • What is redis ?
  • Why redis ?
  • Setup redis in windows using multiple methods
  • First code using redis

What is redis ?

Redis is an open source (BSD licensed) in-memory data structure store which are used as

  • database
  • cache
  • message broker

supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperlogs, and geospatial indexes with radius queries.

Features

Redis has built-in feature which are

  1. Replication
  2. Lua scripting
  3. LRU eviction
  4. Transactions

high availability

Redis provide high availability using following two ways

  1. Redis Sentinel
  2. Automatic partitioning with Redis Cluster.

Redis Atomic operations

Atomic operations in concurrent programming are program operations that run completely independently of any other processes

You can run atomic operations on these types

  1. appending to a string
  2. incrementing the value in a hash
  3. pushing an element to a list
  4. computing set intersection
  5. union
  6. difference
  7. getting the member with highest ranking in a sorted set.

Why redis ?

Redis combines the in-memory schema-less design with optimized data structures and versatile modules that adapt to your data needs.

Provide you with a result which is capable of high performance it is a multi-purpose database that scales easily like a simple key-value data store but delivers sophisticated(well mannered) functionality with great simplicity.

Redis is built to provide the highest

Throughput (millions of operations/second) at the lowest latencies (< 1ms), with the least system resources.

optimized for execution with O (1) complexity

Redis allows access to discrete elements within objects, eliminating serialization/deserialization and processing overheads.

Based on a single-threaded lock-free architecture, it supports an easy-to-parse networking protocol, pipelining for reduced latency, and accelerated command execution and connection pooling for lower setup/teardown overheads.

Setup redis in windows using multiple methods

To Setup redis in windows their is easiest way which is Redis Cloud

Redis Cloud

It is a cloud base database it is the easiest way to setup redis in your system is redis cloud so we will be following few steps which are

Step1

Sign-up for a free Redis Cloud account from here

Now fill your credentials in this form as shown below accordingly,

after writing all credential just press get started button at the end of form

Step 2

Now open your given email to open the link sent to your email for activation of your account and complete your signup process

press activate button to open the link as shown in figure below.

and you will be redirected to your account mian page

Step 3

Now we will first select our new subscription so for free starting first we will click on one from the given cloud services as shown in figure below in my case it was aws

and now click your essential plan in my case it was 30MB as shown in figure and than write your subscription name in my case it was practice and than click on create button

Step 4

Now we will create a new database to setup database endpoint for this first do databases option as shown in figure

then click on + sign as shown in figure below

Now write your database name in the box and than click on activate button as shown in figure below

your database will be password protected and in the configure section you can find your database end point as shown in figure

Step 5

As our Redis instance is ready the next step is to connect to Redis and verify that it’s working.

The easiest way to do this is to test it with “redis-cli” which is Redis command line interface.

So we will now install Redis command line interface

Download and install Redis msi package from Here.

The package installs redis-cli.exe. Even though it is an older version of Redis, it is compatible with the later versions of Redis Cloud.

you will be redirected to a page where you will scroll down to latest version release and click the .msi file as shown in figure below

and after .msi file download run it for installation and then press next button as shown below

again press next and also select check box

and now select check box to set up path environment variable and set your location after this press next as shown below

now next window will show you which on which port redis will be running and press next

now if you want to set max limit you set it otherwise leave it default and press next

and press install

and at last press finish

Step 6

Now we will connect Redis using redis-cli using following method

so open your terminal and their are multiple ways to connect our redis with which are

case 1 run locally with default port

first we will run our Redis locally (127.0.0.1) with the default port, 6379 by using follwoing command

redis-cli

case 2 connect with redis cloud using our database endpoint

for this we will use following syntax

redis-cli -h URL -p portno-a thisismypassword

in above syntax URL is the database endpoint (excluding :port no)and thisismypassword is our database password both of them can be found in configure section of our database in redis cloud and port no is given with end point as shown below

so we will put all of them with our synatx and write command in our terminal as shown in figure below

in my case our inputs were

URL: redis-14450.c80.us-east-1–2.ec2.cloud.redislabs.com

port no : 14450

password:fWFH74uHAicHhBq0jcQ1helhOjjjRgLm

Step 7

Testing the connection

Redis-cli will take you to a prompt with the URL and the port number if it can successfully connect to Redis.

You can then verify whether the server is responding to your queries with basic commands

  1. Ping this returns PONG
  2. set foo bar this returns OK
  3. get foo this returns bar.

So we will run these commands and these were our outputs

and by using databse url we will find this answers

Hurry! we have successfully setup redis on our windows

First code using redis

Redis client libraries are available in more than 50 programming languages.

So I will be implementing my first code with Node.js

  1. First we you should have node.js installed in our system which you can install from here
  2. we will create a folder and initialized it with
npm init

3. Now we will install redis for node.js from following command

npm install redis

4. Now we will create a file named app.js in our folder by following old manual way or by writing following command in our terminal

type nul>app.js

5.Now open the file and we will write the code for which we will use our database endpoint and its password for performing the testing commands which we perform above and following is the code and each line usage

and now we will open our terminal and in our root directory of our folder we will run following command

node app.js

Hurry!!!! we perform our first node.js and redis operation.

Conclusion

Congratulations you learn how to setup redis in your system how to confirm or test connectivity and you performed your first node.js and redis code.

if you like my you blog so follow me or if you have any suggestion give it without hesitation and you can connect with me at

LinkedIn

--

--