DEV Community

Mahesh K
Mahesh K

Posted on

R Language : Connect to Redis Database

Let's learn how to connect Redis database with R. There are some databases like Redis that are often used for specific set of data for example say gaming servers, ranking, temperature monitor etc. R has few open source and few premium packages that allows you to connect with the Redis database.

So here I am taking a look at the Redux package in R that allows you to connect with the redis database. There are few other Redis specific packages too that helps with connection.

You can check the video instruction here. R Language : Connect to Redis Database.

Step 1. Install the Drivers

There are multiple drivers for the connection with the redit database. However let's stick to the one which is actively developed. Here redux driver is useful for connecting to redis database.

You can install the package by following code in the R shell.

install.packages("redux")
Enter fullscreen mode Exit fullscreen mode

After that you can get installed redux library.

Step 2. Create Connection

Now that you have installed the library you can create the hireredis object establish the connection with the server.

r <- redux::hiredis()
Enter fullscreen mode Exit fullscreen mode

Here , you will notice that by default it will connect to the redis on (127.0.0.1) and port 6379.

You can execute redis$PING()

Now from here you can use the redis_api to connect with multiple redis commands.

Step 3. Explore the specific queries

Now that you have learned how to connect redis with the R and managed to execute some basic commands. From here you have to explore further for the additional queries.

You may want to read more about the queries from the Rdocumentation for Redux.

Additional references:

  1. You can also learn how to Connect R language to MySQL database.
  2. Learn how to connect to SQLite from R Language.
  3. Learn how to connect to CouchDB from R Language
  4. Learn how to connect R language to MongoDB database.

Top comments (0)