Use Redis extension in Yii2

Source: Internet
Author: User

Use Redis extension in Yii2

Redis is a good Nosql database. Its advantage over Memcached is that it can persist data. To use Redis in Yii2, you must first expand Redis. You can add redis in composer. json.

"require": {        "php": ">=5.4.0",        "yiisoft/yii2": ">=2.0.5",        "yiisoft/yii2-bootstrap": "*",        "yiisoft/yii2-swiftmailer": "*",        "yiisoft/yii2-smarty": "*",        "yiisoft/yii2-redis": "*"    },

Then use the command composer update, or directly use the command composer update -- prefer-dist yii-soft/yii2-redis.

The next step is to configure the component.

// Redis 'redis '=> ['class' => 'yii \ redis \ connection', 'hostname' => '2017. 0.0.1 ', 'Port' => 6379, 'database' => 0, // by default, there are 16 databases 0-15. For a cluster, there is only one 0.],

Finally, you can use it.

$redis = Yii::$app->redis;$redis->set('city', 'Beijing');$value = $redis->get('city');echo 'The value of city in redis is: ', $value;

 

The problem of Yii2 inline Script Loading failure caused by Pjax in Yii2

Yii2 implements password Modification

Yii User Login Mechanism

Introduce js and css files in Yii

Incomplete Yii Solution

Yii CGridView basic usage

Yii framework distributed cache Implementation Scheme

Yii details: click here
Yii: click here

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.