[root@master html]# vim /var/www/html/ping.php<?php
//连接本地的 Redis 服务
$redis= new Redis();$redis->connect('192.168.16.128', 6379);echo"Connection to server sucessfully";
//查看服务是否运行
echo"Server is running: ".$redis->ping();
?>
[root@master ~]# vim /var/www/html/string.php<?php
//连接本地的 Redis 服务
$redis= new Redis();$redis->connect('192.168.16.128', 6379);echo"Connection to server sucessfully";
//设置 redis 字符串数据
$redis->set("linux", "Linux Redis test");
// 获取存储的数据并输出
echo"Stored string in redis:: ".$redis->get("linux");
?>
[root@master html]# vim list.php <?php
//连接本地的 Redis 服务
$redis= new Redis();$redis->connect('192.168.16.128', 6379);echo"Connection to server sucessfully";
//存储数据到列表中
$redis->lpush("test-list", "Redis");$redis->lpush("test-list", "Mongodb");$redis->lpush("test-list", "Mysql");
// 获取存储的数据并输出
$arList=$redis->lrange("test-list", 0 ,5);echo"Stored string in redis";
print_r($arList);
?>
[root@master html]# vim keys.php<?php
//连接本地的 Redis 服务
$redis= new Redis();$redis->connect('192.168.16.128', 6379);echo"Connection to server sucessfully";
// 获取数据并输出
$arList=$redis->keys("*");echo"Stored keys in redis:: ";
print_r($arList);
?>
~