tencent cloud


Connection Sample for Python

Last updated: 2022-04-25 15:59:07

Preparations before running:
Download and install redis-py.

Sample code:

#!/usr/bin/env python3
#-*- coding: utf-8 -*- 
import redis 
#Replace with the connected instance host and port here 
host = '192.xx.xx.195' 
port = 6379 
#Replace with the instance ID and password here 
#When connecting, specify the AUTH information through the `password` parameter. If you connect through the default account, it is `pwd`. If you connect through a custom account, it is `user+'@'+pwd`
r = redis.StrictRedis(host=host, port=port, password=user+'@'+pwd) 
#Database operations can be performed after the connection is established. For more information, visit https://github.com/andymccurdy/redis-py 
r.set('name', 'python_test'); 
print r.get('name')

Execution result:

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support