Access a DCS Redis instance through Predis on an ECS in the same VPC. For more information about how to use other Redis clients, visit the Redis official website.
For details, see Viewing Details of a DCS Instance.
yum install php-devel php-common php-cli
php --version
wget https://github.com/predis/predis/archive/refs/tags/v1.1.10.tar.gz
This version is used as an example. To download Predis clients of other versions, visit the Redis or PHP official website.
mv predis-1.1.10 predis
<?php require 'predis/autoload.php'; Predis\Autoloader::register(); $client = new Predis\Client([ 'scheme' => 'tcp' , 'host' => '{redis_instance_address}' , 'port' => {port} , 'password' => '{password}' ]); $client->set('foo', 'bar'); $value = $client->get('foo'); echo $value; ?>
<?php require 'predis/autoload.php'; $servers = array( 'tcp://{redis_instance_address}:{port}' ); $options = array('cluster' => 'redis'); $client = new Predis\Client($servers, $options); $client->set('foo', 'bar'); $value = $client->get('foo'); echo $value; ?>
{redis_instance_address} indicates the actual IP address or domain name of the DCS instance and {port} is the actual port number of DCS instance. For details about how to obtain the IP address/domain name and port, see 1. Change the IP address/domain name and port 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 required, delete the line that contains "password".