Home> Database> Redis> body text

How to implement redis cache

WBOY
Release: 2023-05-30 18:52:45
forward
1418 people have browsed it

1. Use the Pagoda panel to build the WeQing server first.

2. Open PHP management, click Install Extension, and install the redis extension.

3. After installing the redis extension, open the redis management and click Performance Adjustment to modify the port number, redis password and a series of operations.

4. Log in to the WeQing backend, click Site Settings, find Performance Optimization in Common Tools, enter the Performance Optimization interface, and see if the PHP extension environment already supports redis.

5. Open the WeQing code, location: /www/wwwroot/your site domain name/data/config.php,

modify the code snippet, change mysql to redis

Then add the following code

// -------------------------- CONFIG REDIS ----------------------------// $config['setting']['redis']['server'] = '127.0.0.1'; //默认本地,你也可以用云库地址(远程) // -------------------------- CONFIG REDIS ----------------------------// $config['setting']['redis']['server'] = '127.0.0.1'; //默认本地,你也可以用云库地址(远程) $config['setting']['redis']['port'] = 6379; //默认端口 $config['setting']['redis']['pconnect'] = 1; $config['setting']['redis']['auth'] = ; //redis密码, 默认为空 $config['setting']['redis']['timeout'] = 1;
Copy after login

6. Then log in to the Weiqing backend, click site settings, find performance optimization in common tools, enter the performance optimization interface, and see if the config setting has been turned on. That’s it. So far, redis has been configured.

7. Next, write the connection code about redis:

/* redis链接 */ function connectionRedis(){ global $_W,$_GPC; $redisConfig = $_W["config"]['setting']['redis']; //微擎 $redis = new Redis(); $redis->pconnect($redisConfig['server'], $redisConfig['port']); $redis -> auth($redisConfig['auth']); return $redis; }
Copy after login

8. Next, you can use the redis function to your heart's content.

The above is the detailed content of How to implement redis cache. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
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
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!