VOOZH about

URL: https://redis.io/docs/latest/develop/clients/ioredis/connect/

⇱ Connect to the server | Docs


{"categories":["docs","develop","stack","oss","rs","rc","oss","kubernetes","clients"],"description":"Connect your Python application to a Redis database","duplicateOf":"head:data-ai-metadata","location":"body","title":"Connect to the server","tableOfContents":{"sections":[{"id":"basic-connection","title":"Basic connection"},{"id":"connect-to-a-redis-cluster","title":"Connect to a Redis cluster"},{"id":"connect-to-your-production-redis-with-tls","title":"Connect to your production Redis with TLS"}]},"codeExamples":[]}

Connect to the server

Connect your Python application to a Redis database

Basic connection

Connect to localhost on port 6379:

const redis = new Redis();

You can also specify a full set of connection options:

const redis = new Redis({
 port: 6379,
 host: "127.0.0.1",
 username: "default",
 password: "my-password",
 db: 0,
});

Store and retrieve a simple string.

await redis.set('foo', 'bar');
const value = await redis.get('foo');
console.log(value); // >>> bar

Connect to a Redis cluster

To connect to a Redis cluster, use Redis.Cluster(), passing an array of endpoints.

const redis = new Redis.Cluster([
 {
 host: '127.0.0.1',
 port: 6380,
 password: 'my-password',
 username: 'default',
 },
 {
 host: '127.0.0.1',
 port: 6381,
 password: 'my-other-password',
 username: 'default',
 },
 // ...
]);

Connect to your production Redis with TLS

When you deploy your application, use TLS and follow the Redis security guidelines.

const redis = new Redis({
 host: "localhost",
 //...
 tls: {
 key: readFileSync('./redis_user_private.key'),
 cert: readFileSync('./redis_user.crt'),
 ca: fs.readFileSync('./redis_ca.pem'),
 },
});

On this page