Skip to main content

Connect With TLS

If you enabled TLS (SSL) on your database, then you need to configure your client too. When you click on Connect button, you can copy the code that is required for your client. Also, below you can find example client configurations with TLS enabled. If you are using a Redis client that is not listed below, please check the documentation of your client.

Node.js#

Library: node redis

Example:

var redis = require('redis');
var host = 'YOUR_ENDPOINT';
var port = 'YOUR_PORT';
var password = 'YOUR_PASSWORD';
var client = redis.createClient ({
port : port,
host : host,
password: password,
tls: {}
});
client.on("error", function(err) {
throw err;
});
client.set('foo','bar');
client.get('foo', function(err, response){
if(err) {
throw err;
}
else {
console.log(response);
client.quit();
}
});

Python#

Library: redis-py

Example:

import redis
r = redis.Redis(
host= 'YOUR_ENDPOINT',
port= 'YOUR_PORT',
password= 'YOUR_PASSWORD', ssl=True)
r.set('foo','bar')
print(r.get('foo'))

Java#

Library: jedis

Example:

Jedis jedis = new Jedis("YOUR_ENDPOINT", "YOUR_PORT", true);
jedis.auth("YOUR_PASSWORD");
jedis.set("foo", "bar");
String value = jedis.get("foo");
System.out.println(value);

GoLang#

Library: redigo

Example:

func main() {
c, err := redis.Dial("tcp", "YOUR_ENDPOINT:YOUR_PORT", redis.DialUseTLS(true))
if err != nil {
panic(err)
}
_, err = c.Do("AUTH", "YOUR_PASSWORD")
if err != nil {
panic(err)
}
_, err = c.Do("SET", "foo", "bar")
if err != nil {
panic(err)
}
value, err := redis.String(c.Do("GET", "foo"))
if err != nil {
panic(err)
}
println(value)
}