您的位置:首页 > 数据库 > Redis

在windows下和linux下安装redis

2016-06-12 21:46 489 查看
windows 下运行效果:





如何安装:

第一步redis安装:(https://github.com/dmajkic/redis/downloads)

1、首先确认下载包为64位的还是32位的

2、下载cccc

3、解压下载包得到以下文件:

cygwin1.dll
redis-benchmark.exe //性能测试,用以模拟同时N个客户端发送M个sets/gets查询
redis-check-aof.exe //更新日志检查
redis-check-dump.exe //本地数据库检查
redis-cli.exe
redis-server.exe 服务程序
redis.conf 配置文件


4、解压好的安装文件放到D盘目录后,文件夹改名为redis(方便下面讲解),配置redis.conf,(先不做配置,默认就好)

5、启动redis

开启cmd窗口,输入命令:

开启 redis 命令

redis-server.exe  redis.windows.conf


开启redis成功,

6、另起一cmd窗口输入命令:

redis-cli.exe -h 127.0.0.1 -p 6379


下面就可在此窗口进行测试:

输入: set key1 HelloWorld
get key1
如果输出:HelloWorld 表示你的redis已经安装成功了
开启命令

redis-server.exe  redis.windows.conf


下面进行第二步:php扩展Redis功能, 下载https://github.com/nicolasff/phpredis/downloads

 1 首先,查看所用php编译版本V6/V9 在phpinfo()中查看

 我的是MSVC9(Visual C++ 2008)所以下载的是 phpredis_5.4_vc9_ts.7z

 2 将下载的php_igbinary.dll、php_redis.dll放在php扩展目录中(ext),并修改配置文件php.ini

 extension=php_igbinary.dll

 extension=php_redis.dll

 3 重新启动服务,查看phpinfo(),找到以下内容表示成功

redis
Redis Support            enabled
Redis Version            2.2.3


  4 用PHP测试

<?php

phpinfo();
$redis = new Redis();
$redis->connect("127.0.0.1","6379");
$redis->set("key1","Hello world");
echo $redis->get("key1");

?>


5:php 操作reds命令  http://www.cnblogs.com/jackluo/p/3412670.html
6:Redis命令中文文档:http://redisdoc.com/

linux效果:





在linux下安装redis教程,前提是你要安装gcc否则你是不能安装redis的

$ yum install gcc-c++
$ wget http://download.redis.io/releases/redis-2.8.17.tar.gz $ tar xzf redis-2.8.17.tar.gz
$ cd redis-2.8.17
$ make

make完后 redis-2.8.17目录下会出现编译后的redis服务程序redis-server,还有用于测试的客户端程序redis-cli,两个程序位于安装目录 src 目录下:

下面启动redis服务

$ cd src
$ ./redis-server

如果想让redis-server服务想运行在后台可以使用一下命令

./redis-server &

设置redis密码
[root@iZ254lfyd6nZ src]# ./redis-cli
127.0.0.1:6379> get name
"tanglei1234"
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""
127.0.0.1:6379> config set requirepass haoyun(设置密码)
OK
127.0.0.1:6379> config get requirepass
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth matian963
OK
127.0.0.1:6379> get name
"tanglei1234"
127.0.0.1:6379>
Connection closed by foreign host.
※※※  注意这种方式启动redis 使用的是默认配置。也可以通过启动参数告诉redis使用指定配置文件使用下面命令启动

redis.conf是一个默认的配置文件。我们可以根据需要使用自己的配置文件。
启动redis服务进程后,就可以使用测试客户端程序redis-cli和redis服务交互了。
比如
$ cd src
$ ./redis-cli
redis>auth 密码
redis>set foo bar
OK
redis>get foo
 


以上测试如果不出任何问题这样你的linux服务器上的redis就安装ok拉!

接下来安装php_redis.dll扩展让php支持redis

PHP 使用 Redis

安装  

安装前请将php-devel安装上

<pre name="code" class="python">$ yum install php-devel
$ wget https://github.com/phpredis/phpredis/archive/2.2.4.tar.gz $ tar zxf 2.2.4.tar.gz
$ cd phpredis-2.2.4
$ /usr/bin/phpize


如果/usr/local/bin/phpize 执行出现问题可以使用whereis phpize查到phpize目录在什么位置列如

whereis phpize

$ ./configure --with-php-config=/usr/bin/php-config
如果./configure --with-php-config=/usr/bin/php-config执行出现问题可以使用whereis php-config 查到php-config列如
whereis php-config
最后
make && make install
最后让php加载redis扩展  首先打开php.ini   如果不知道,用whereis php.ini  找到

vi /etc/php.ini     在php.ini  的任意行添加以下内容 extension=redis.so    添加完成之后保存并重启Apache服务器  systemctl restart httpd    在Apache的域名下新建php文件里输入phpinfo()查看

<?php
$redis = new Redis();
$redis->connect('192.168.1.211', 6379);
$redis->set('key','val');
echo $redis->get('key');
?>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: