Home >PHP Framework >YII >What should I do if yii2 redis reports an error?
yii2 What should I do if redis reports an error?
yii2-redis installation and configuration
Recommended related tutorials: yii framework
Install redis Extension:
1. Install through composer, go to the project root directory cmd and run (recommended)
php composer.phar require --prefer-dist yiisoft/yii2-redis
or add
"yiisoft/yii2-redis": "~2.0.0"
to the composer.json file of the corresponding project
2. Manual installation
Click to download: yii2.0-redis extension
Put the downloaded extension file under vendor/yiisoft/ and name it yii2-redis
Modify extensions.php under vender/yiisoft/ and add the redis extension
'yiisoft/yii2-redis' => array ( 'name' => 'yiisoft/yii2-redis', 'version' => '2.2.0.0', 'alias' => array ( '@yii/redis' => $vendorDir . '/yiisoft/yii2-redis', ), ),
After the above two methods are installed
Build redis in the environment under windows
Download address: https://github.com/dmajkic/redis/downloads There are two packages in the downloaded package,
One is 32-bit and the other is 64-bit. Choose according to your actual situation,
Copy this folder to other places, such as the D:\redis directory.
Open a cmd window, use the cd command to switch directories to D:\redis and run redis-server.exe redis.conf
After running, the following interface will appear:
Environment building redis under linux
To install Redis on Ubuntu, open a terminal and enter the following command:
$sudo apt-get update $sudo apt-get install redis-server
This will install it on your computer Redis
Start Redis
$redis-server
Check whether redis is still running
$redis-cli
This will open a Redis prompt, as shown below:
redis 127.0.0.1:6379>
In In the above prompt information: 127.0.0.1 is the IP address of the machine, and 6379 is the port where the Redis server runs. Now enter the PING command, as shown below:
redis 127.0.0.1:6379> ping PONG
This means that you have successfully installed Redis on your computer.
Installing Redis Desktop Manager on Ubuntu
To install Redis Desktop Manager on Ubuntu, you can download the package from http://redisdesktop.com/download and install it.
Redis Desktop Manager will give you the user interface to manage Redis keys and data.
Indicates that the redis service has been started
Configure Yii component
'redis' => [ 'class' => 'yii\redis\Connection', 'hostname' => 'localhost', 'port' => 6379, 'database' => 0, ], 这样我们的redis就配置完成了,接下来就是验证了 public function actionIndex() { Yii::$app->redis->set('test','111'); //设置redis缓存 echo Yii::$app->redis->get('test'); //读取redis缓存 exit; return $this->render('index'); }
The page outputs "111", which means that the redis configuration is successful
The above is the detailed content of What should I do if yii2 redis reports an error?. For more information, please follow other related articles on the PHP Chinese website!