tencent cloud

Feedback

PHP Connection Sample

Last updated: 2022-07-05 10:55:17

Preparations before running:

Download the phpredis client.

Sample code:

<?php
/**For the following parameters, enter your Redis instance's private IP, port number, instance ID and password*/
$host = "192.xx.xx.2";
$port = 6379;
$instanceid = "c532952f-55dc-4c22-a941-63057e560788";
$pwd = "123tj6na";
 $redis = new Redis();
// Connect to Redis
if ($redis->connect($host, $port) == false) {
  die($redis->getLastError());
}
// Authenticate
if ($redis->auth($instanceid . ":" . $pwd) == false) {
  die($redis->getLastError());
}

/**You can start manipulating the Redis instance. For more information, see https://github.com/phpredis/phpredis */

// Set the Key
if ($redis->set("redis", "tencent") == false) {
  die($redis->getLastError());
}
echo "set key redis suc, value is:tencent\n";

// Get the Key
$value = $redis->get("redis");
echo "get key redis is:".$value."\n";
?>

Execution result:

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support