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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses best practices for deploying Yii applications in cloud-native environments, focusing on scalability, reliability, and efficiency through containerization, orchestration, and security measures.

The article discusses key considerations for using Yii in serverless architectures, focusing on statelessness, cold starts, function size, database interactions, security, and monitoring. It also covers optimization strategies and potential integrati

The article discusses implementing real-time data synchronization using Yii and WebSockets, covering setup, integration, and best practices for performance and security.

The article discusses strategies for testing Yii applications using Codeception, focusing on using built-in modules, BDD, different test types, mocking, CI integration, and code coverage.

Yii's built-in testing framework enhances application testing with features like PHPUnit integration, fixture management, and support for various test types, improving code quality and development practices.

The article discusses key considerations for deploying Yii applications in production, focusing on environment setup, configuration management, performance optimization, security, logging, monitoring, deployment strategies, and backup/recovery plans.

The article discusses Yii's benefits for SaaS development, focusing on performance, security, and rapid development features to enhance scalability and reduce time-to-market.

The article discusses implementing service discovery and load balancing in Yii microservices, detailing steps and best practices for efficient communication and workload distribution.
