このページは、お客様の言語ではご利用いただけません。Huawei Cloudは、より多くの言語バージョンを追加するために懸命に取り組んでいます。ご協力ありがとうございました。

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 Redis on phpredis (PHP)

Updated on 2024-07-29 GMT+08:00

This section describes how to connect to Redis on phpredis. For more information about how to use other Redis clients, visit the Redis official website.

NOTE:

The operations described in this section apply only to single-node, master/standby, and Proxy Cluster instances. To use phpredis to connect to a Redis Cluster instance, see the phpredis description.

Prerequisites

  • A DCS Redis instance has been created and is in the Running state.
  • An ECS has been created. For details about how to create an ECS, see the Elastic Cloud Server User Guide.
  • If the ECS runs the Linux OS, ensure that the GCC compilation environment has been installed on the ECS.

Connecting to Redis on phpredis

  1. View the IP address and port number of the DCS Redis instance to be accessed.

    For details, see Viewing Details of a DCS Instance.

  2. Log in to the ECS.

    The following uses CentOS as an example to describe how to access an instance through phpredis.

  3. Install GCC-C++ and Make compilation components.

    yum install gcc-c++ make

  4. Install the PHP development package and CLI tool.

    Run the following yum command to install the PHP development package:

    yum install php-devel php-common php-cli

    After the installation is complete, run the following command to query the PHP version and check whether the installation is successful:

    php --version

  5. Install the phpredis client.

    1. Download the source phpredis package.

      wget http://pecl.php.net/get/redis-5.3.7.tgz

      This version is used as an example. To download phpredis clients of other versions, visit the Redis or PHP official website.

    2. Decompress the source phpredis package.

      tar -zxvf redis-5.3.7.tgz

      cd redis-5.3.7

    3. Command before compilation.

      phpize

    4. Configure the php-config file.

      ./configure --with-php-config=/usr/bin/php-config

      The location of the file varies depending on the OS and PHP installation mode. You are advised to locate the directory where the file is saved before the configuration.

      find / -name php-config

    5. Compile and install the phpredis client.

      make && make install

    6. After the installation, add the extension configuration in the php.ini file to reference the Redis module.

      vim /etc/php.ini

      Add the following configuration:

      extension = "/usr/lib64/php/modules/redis.so"
      NOTE:

      The redis.so file may be saved in a different directory from php.ini. Run the following command to locate the directory:

      find / -name php.ini

    7. Save the configuration and exit. Then, run the following command to check whether the extension takes effect:

      php -m |grep redis

      If the command output contains redis, the phpredis client environment has been set up.

  6. Access the DCS instance by using phpredis.

    1. Edit a redis.php file.
      <?php
          $redis_host = "{redis_instance_address}";
          $redis_port = {port};
          $user_pwd = "{password}";
          $redis = new Redis();
          if ($redis->connect($redis_host, $redis_port) == false) {
             die($redis->getLastError());
          }
          if ($redis->auth($user_pwd) == false) {
              die($redis->getLastError());
          }
          if ($redis->set("welcome", "Hello, DCS for Redis!") == false) {
              die($redis->getLastError());
          }
          $value = $redis->get("welcome");
          echo $value;
          $redis->close();
      ?>

      {redis_instance_address} indicates the example IP address of the DCS instance and {port} indicates the port number of the DCS instance. For details about how to obtain the IP address and port, see 1. Change them as required. {password} indicates the password used to log in to the chosen DCS Redis instance. This password is defined during DCS Redis instance creation. If password-free access is enabled, shield the if statement for password authentication.

    2. Run the php redis.php command to access the DCS instance.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback