DEV Community

Cover image for How to use Redis without installing it in Windows/Linux
Prashant Dwivedi
Prashant Dwivedi

Posted on

How to use Redis without installing it in Windows/Linux

Very often we feel the need of key-value pair database for our projects. However, using our main database for this purpose can be really tedious and an unnecessary task.

During such times the only solution that comes to our mind is Redis!.

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. One can make use of Redis whenever there is need of key-value pair database.

Example: One good example of using the Redis is to store the status of some action, like if someone makes a request of password reset then we can allow the password reset only in next 5 min after the request is made. Now to maintain the status for this 5 minute we can make use of Redis. We can store some sort of key associated with this user which can auto expire in 5min.

Using Redis

Having said that, let's see how we can make use of Redis in our projects without any installations.

One the major obstacles while working with Redis is that you need to install it in your machine and then launch the Redis server to use it. This can be done easily with Linux based system but unfortunately it can't be done that easily in Window's machine as Redis is not officially supported on windows ( as per my knowledge ) so you need to do some workaround like WSL, etc.

Redis Cloud

Just head on to https://app.redislabs.com/ and make your account on redis labs page.

It offers a free plan which includes 30MB of space ( which is enough for storing key-value pairs for small projects ) and 1 dedicated database

Screenshot of Making the Database
Image description

Upon successful creation of database we get to see following dashboard
Image description

Just Click on the database and copy the following credentials

  • Public endpoint This is of the format: host:port Image description
  • Default user password Image description

Now since we have these credentials we can connect to our database and use Redis as usual.

Below is the example with Python. I have saved the credentials in environment file. One can directly put the credentials below. Eg: In place of os.getenv("REDIS_HOST") directly put the host url.

import redis
red = redis.Redis(
    host=os.getenv("REDIS_HOST"),
    port=os.getenv("REDIS_PORT"), 
    password=os.getenv("REDIS_PASSWORD")
)

red.set("key", "value")
print(red.get("key")

Enter fullscreen mode Exit fullscreen mode

Top comments (0)