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;
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; }
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!