安装配置redis服务器
$ wget http://download.redis.io/releases/redis-3.0.5.tar.gz $ tar xzf redis-3.0.5.tar.gz $ cd redis-3.0.5 $ make
安装完毕后,修改配置文件,redis.conf
daemonize no #开启redis后台运行
参数说明http://www.runoob.com/redis/redis-conf.html
运行redis
$ src/redis-server redis.conf
检验是否运行,进入redis操作进程
$ src/redis-cli >ping >pong代表运行成功
开启6739端口,以便于远程访问
-A INPUT -p tcp -m tcp --dport 6379 -j ACCEPT
laravel5.1安装predis支持
"require": { "php": ">=5.5.9", "laravel/framework": "~5.1.8", "predis/predis": "v1.0.3" //predis },
然后项目目录执行composer install
laravel配置redis服务器configdatabase.php
'redis' => [ 'cluster' => false, 'default' => [ 'host' => '192.168.1.19', 'port' => 6379, 'database' => 0, ], ],
基本测试
E: pwwwlaravel5-1 estsExampleTest.php public function testRedis(){ $response = $this->call('GET', '/redis', ['name' => 'Taylor']); var_dump($response); }
E: pwwwlaravel5-1appHttp outes.php Route::get('redis', [ 'uses' => 'RedisController@index', 'as' => 'redis' ]);
E: pwwwlaravel5-1appHttpControllersRedisController.php
<?php namespace AppHttpControllers; use IlluminateHttpRequest; use AppHttpRequests; use AppHttpControllersController; use Redis; class RedisController extends Controller { public function index() { Redis::set("user:profile:1",111); $user = Redis::get('user:profile:1'); echo $user; } }
111