阿里云PHP Redis代码示例

测试代码示例

<?php
/* 这里替换为连接的实例host和port */
$host = "localhost";
$port = 6379;

/* 这里替换为实例id和实例password */
$user = "test_username";
$pwd = "test_password";

$redis = new Redis();
if ($redis->connect($host, $port) == false) {
die($redis->getLastError());
}

/* user:password 拼接成AUTH的密码 */
if ($redis->auth($user . ":" . $pwd) == false) {
die($redis->getLastError());
}

/* 认证后就可以进行数据库操作,详情文档参考https://github.com/phpredis/phpredis */
if ($redis->set("foo", "bar") == false) {
die($redis->getLastError());
}

$value = $redis->get("foo");
echo $value;

?>
posted @ 2015-06-29 10:57  谦信君  阅读(2306)  评论(0编辑  收藏  举报