tencent cloud

All product documents
TencentDB for Redis®
PHP Connection Sample
Last updated: 2024-11-05 10:10:15
PHP Connection Sample
Last updated: 2024-11-05 10:10:15
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:

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

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
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon