Halaman ini belum tersedia dalam bahasa lokal Anda. Kami berusaha keras untuk menambahkan lebih banyak versi bahasa. Terima kasih atas dukungan Anda.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
Software Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Connecting to Memcached on the Python-binary-memcached (Python)

Updated on 2024-10-28 GMT+08:00

Access a DCS Memcached instance using a Python client on an ECS in the same VPC.

Prerequisites

  • The DCS Memcached instance you want to access is in the Running state.
  • Log in to the ECS. For details on how to create ECSs, see the Elastic Cloud Server User Guide.
    NOTE:

    An ECS can communicate with a DCS instance that belongs to the same VPC and is configured with the same security group.

    • If the ECS and DCS instance are in different VPCs, establish a VPC peering connection to achieve network connectivity between the ECS and DCS instance. For details, see Does DCS Support Cross-VPC Access?
    • If different security groups have been configured for the ECS and DCS instance, set security group rules to achieve network connectivity between the ECS and DCS instance. For details, see How Do I Configure a Security Group?
  • Python has been installed on the ECS. The recommended version is 2.7.6 or later.
  • You have obtained the python-binary-memcached-x.y.z.zip dependency package.
    NOTE:

    x.y.z indicates the version of the dependency package. The latest version is recommended.

Connecting to Memcached on the Python-binary-memcached

  1. Log in to the DCS console.
  2. Click in the upper left corner of the management console and select the region where your instance is located.
  3. In the navigation pane, choose Cache Manager.
  4. On the Cache Manager page, click the name of the DCS Memcached instance you want to access. Obtain the IP address or domain name and port number of the instance.
  5. Upload the obtained dependency package (for example, the python-binary-memcached-x.y.z.zip package) to the created ECS.
  6. Log in to the ECS.
  7. Run the following commands to install the dependency package:

    unzip -xzvf python-binary-memcached-x.y.z.zip

    cd python-binary-memcached-x.y.z

    python setup.py install

    NOTE:

    If an error is reported during the installation, use the apt or yum installation method. For example, to install the dependency package by using the apt method, run the following commands:

    apt install python-pip;

    pip install python-binary-memcached;

  8. Create a Python file named dcs_test.py, copy the following Python code to the file, and modify the code.

    • Example code for the password mode
      Change ip or domain name:port to the IP address/domain name and port number obtained in 4. Set userName and password respectively to the username and password of the Memcached instance.
      import bmemcached
      client = bmemcached.Client(('ip or domain name:port'), 'userName', 'password')
      print "set('key', 'hello world!')"
      print client.set('key', 'hello world!')
      print "get('key')"
      print client.get('key')
    • Example code for the password-free mode

      Change ip or domain name:port to the IP address/domain name and port number obtained in 4.

      import bmemcached
      client = bmemcached.Client('ip or domain name:port')
      print "set('key', 'hello world!')"
      print client.set('key', 'hello world!')
      print "get('key')"
      print client.get('key')

  9. Run the dcs_test.py file. The following result is displayed.

    # python test.py 
    set('key', 'hello world!')
    True
    get('key')
    hello world!

Kami menggunakan cookie untuk meningkatkan kualitas situs kami dan pengalaman Anda. Dengan melanjutkan penelusuran di situs kami berarti Anda menerima kebijakan cookie kami. Cari tahu selengkapnya

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback