Back to Redis

ioredis guide (JavaScript)

content/develop/clients/ioredis/_index.md

latest1.6 KB
Original Source

ioredis is a Redis client for Node.js/JavaScript. The sections below explain how to install ioredis and connect your application to a Redis database.

{{< note >}}Redis actively maintains and supports ioredis since it is in widespread use, but for new projects, we recommend using our newer Node.js client [node-redis]({{< relref "/develop/clients/nodejs" >}}). See [Migrate from ioredis]({{< relref "/develop/clients/nodejs/migration" >}}) if you are interested in converting an existing ioredis project to node-redis. {{< /note >}}

ioredis requires a running Redis server. See [here]({{< relref "/operate/oss_and_stack/install/" >}}) for Redis Open Source installation instructions.

Install

To install ioredis, run:

bash
npm install ioredis

Connect and test

Connect to localhost on port 6379.

{{< clients-example set="landing" step="connect" lang_filter="ioredis" >}} {{< /clients-example >}}

Store and retrieve a simple string.

{{< clients-example set="landing" step="set_get_string" lang_filter="ioredis" >}} {{< /clients-example >}}

Store and retrieve a map.

{{< clients-example set="landing" step="set_get_hash" lang_filter="ioredis" >}} {{< /clients-example >}}

When you have finished using a connection, close it with client.quit().

{{< clients-example set="landing" step="close" lang_filter="ioredis" >}} {{< /clients-example >}}

More information

The Github repository has useful information, including API docs and a set of code examples.