Got it

Connection Between Python and the Redis Cluster

Latest reply: Nov 21, 2021 15:42:43 381 4 3 0 0

Hi, everyone! 

Today I'm going to introduce you to the connection between Python and the Redis cluster.

In this case, Python 3.6 is used.

Installation Dependency

Note: The dependency version must be the following:

1. Install Redis-py 2.10.6 first.

Download link:

2. Install redis-py-cluster 1.3.5.

Download Link

Download the file and upload it to the Linux environment.

After the decompression, go to the directory after the decompression.

Executing python3 install

Test Verification Scripts

The following code connects to the Redis in the FusionInsight cluster where the security mode is not enabled.

#!/usr/bin/env python3
from rediscluster import StrictRedisCluste
class RedisCluster(object):
    def __init__(self, conn_list):
        self.conn_list = conn_list
    def connect(self):
        Connecting to the Redis Cluster
        :return: object
            redisconn = StrictRedisCluster(startup_nodes=self.conn_list)
            return redisconn
        except Exception as e:
            print("Error. Failed to connect to the Redis cluster.")
            return False
redis_basis_conn = [{'host': '', 'port': 22400},
                    {'host': '', 'port': 22400},
                    {'host': '', 'port': 22400}]
res = RedisCluster(redis_basis_conn).connect()
if not res:
    print("Failed to connect to the Redis cluster.")
    print("Connecting to the Redis cluster succeeded.")
redis_conn = RedisCluster(redis_basis_conn).connect()
redis_conn.set('name', 'admin')
print("name is: ", redis_conn.get('name'))

Hope you can learn from it, thank you!

  • x
  • convention:

Admin Created Apr 7, 2021 09:44:25

View more
  • x
  • convention:

MVE Created Apr 7, 2021 13:43:41

Well done
View more
  • x
  • convention:

Admin Created Nov 15, 2021 02:32:30

Thanks for your sharing!
View more
  • x
  • convention:

Created Nov 21, 2021 15:42:43

Thanks for sharing this useful info
View more
  • x
  • convention:


You need to log in to comment to the post Login | Register

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits


Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Please bind your phone number to obtain invitation bonus.
Information Protection Guide
Thanks for using Huawei Enterprise Support Community! We will help you learn how we collect, use, store and share your personal information and the rights you have in accordance with Privacy Policy and User Agreement.