Python Connection Example

Last updated: 2020-02-26 15:31:29

Preparations before running:
Download and install redis-py.

Sample Code:

#!/usr/bin/env python 
#-*- coding: utf-8 -*- 
import redis 

#Replace with the connected instance's host and port here 
host = '' 
port = 6379 

#Replace with the instance ID and instance password here 

#When connecting, specify the AUTH information through the password parameter in the format of 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, see 
r.set('name', 'python_test'); 
print r.get('name')

Execution results:

Was this page helpful?

Was this page helpful?

  • Not at all
  • Not very helpful
  • Somewhat helpful
  • Very helpful
  • Extremely helpful
Send Feedback