Home > PHP Framework > YII > body text

What should I do if yii2 redis reports an error?

藏色散人
Release: 2020-04-08 10:54:56
Original
2527 people have browsed it

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
Copy after login

or add

"yiisoft/yii2-redis": "~2.0.0"
Copy after login

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',
        ),
    ),
Copy after login

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:

What should I do if yii2 redis reports an error?

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
Copy after login

This will install it on your computer Redis

Start Redis

$redis-server
Copy after login

Check whether redis is still running

$redis-cli
Copy after login

This will open a Redis prompt, as shown below:

redis 127.0.0.1:6379>
Copy after login

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
Copy after login

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');
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!