Skip to main content

Connect with NodeJS

This example demonstrates how to connect to Dragonfly® from NodeJS using the ioredis library, which is officially supported and compatible with Dragonfly. For more information, see Dragonfly SDKs.


Replace the following placeholders in the code sample with the appropriate values:

DRAGONFLY_URIURL for the Dragonfly connection


Install the ioredis library:

npm install --save ioredis


Create a file named index.js, add the following content and replace the DRAGONFLY_URI placeholder with your Dragonfly instance's connection URI:

const Redis = require('ioredis');

const redis = new Redis('DRAGONFLY_URI'); // Replace with your Dragonfly URI

redis.set('key', 'hello world').then(() => {
return redis.get('key');
}).then((value) => {
console.log('The value of key is:', value);
}).catch((err) => {
console.error('Error:', err);

This code connects to Dragonfly, sets a key named key with the value hello world (without expiration), then retrieves and prints the value of this key.

Run the code

To execute the code, use the following command in your terminal:

node index.js

If everything is set up correctly, the output should be:

The value of key is: hello world