This document provides client code samples for Python to help you access a database with or without SSL encryption enabled.
Prerequisites
Get the account and password for database access. For detailed directions, see Managing Account. Download and install redis-py. The latest version is recommended. Connection Sample Without SSL Encryption Enabled
You need to modify the parameters based on the comments, including IP, port, account, and password for database access.
#!/usr/bin/env python3
import redis
host = '192.xx.xx.195'
port = 6379
user='username'
pwd='password'
r = redis.StrictRedis(host=host, port=port, password=user+'@'+pwd)
r.set('name', 'python_test');
print r.get('name')
Connection Sample With SSL Encryption Enabled
You need to modify the parameters based on the comments, including SSL certificate file, IP, port, account, and password for database access.
import redis3 as redis3
if __name__ == "__main__":
client = redis3.Redis(host="vip", port=6379, password="pwd", ssl=True, ssl_cert_reqs="required",
ssl_ca_certs="ca.pem")
print(client.ping())
Was this page helpful?