Source Link: How to build a redis extension http://www.yii-china.com/post/detail/43.html
To install the Redis extension:
1. Install through composer, run to the project root directory cmd (recommended)
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/, named Yii2-redis
Modify extensions.php under vender/yiisoft/to join 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 installation is completed in both of these ways
The environment under Windows builds Redis
: There are two https://github.com/dmajkic/redis/downloads downloaded in the bag,
One is 32 bits, one is 64 bits. According to the circumstances of their own choice,
Copy this folder to a different location, such as the D:\redis directory.
Open a CMD window and use the CD command to switch directories to D:\redis runredis-server.exe redis.conf
After running, the following interface will appear:
Blob.png
Indicates that the Redis service has started
Configuring component for Yii
‘redis‘ => [ ‘class‘ => ‘yii\redis\Connection‘, ‘hostname‘ => ‘localhost‘, ‘port‘ => 6379, ‘database‘ => 0,],
So our Redis is configured and the next step is to verify
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 the Redis configuration is successful.
How to build a redis extension-yii Chinese network