redis安装和参数
redis的数据备份和恢复
保存数据和保存目录
/bin/redis-cli
127.0.0.1:6379 > SAVE
127.0.0.1:6379 >exit
127.0.0.1:6379> CONFIG GET dir
1) "dir"
2) "/usr/local/redis/data" 保存数据的目录
恢复数据
把数据的dump.rdb放到/bin/目录下
service redis restart 重启redis服务
redis的配置文件的信息
daemonize yes 作为守护进程运行
/var/run/redis.pid 默认pid存放目录
bind 127.0.0.1 绑定主机地址
查看redis的信息命令:
http://blog.csdn.net/wangdaoge/article/details/53024129
/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379 info
PHP的redis模块
redis作为mysql缓存
网址:
http://www.cnblogs.com/hellowzd/p/5163782.html
phpredis的下载地址:
http://pecl.php.net/get/redis-3.1.3.tgz
tar xf redis-3.1.3.tgz
cd redis-3.1.3
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
vim /usr/local/php/lib/php.ini
extension=redis.so
/etc/init.d/php-pfm restart
vim index.php
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379) or die ("could net connect redis server");
$query = "select * from test limit 8";
for ($key = 1; $key < 9; $key++)
{
if (!$redis->get($key))
{
$connect = mysqli_connect('127.0.0.1','root','123');
mysqli_select_db($connect,"mytest");
$result = mysqli_query($connect,$query);
while ($row = mysqli_fetch_assoc($result))
//while ($row = mysqli_fetch_assoc($result))
{
$redis->set($row['id'],$row['name']);
}
$myserver = 'mysql';
break;
}
else
{
$myserver = "redis";
$data[$key] = $redis->get($key);
}
}
echo $myserver;
echo "<br>";
for ($key = 1; $key < 9; $key++)
{
echo "number is <b><font color=#FF0000>$key</font></b>";
echo "<br>";
echo "name is <b><font color=#FF0000>$data[$key]</font></b>";
echo "<br>";
}
?>