How to implement redis caching
This article mainly introduces the relevant knowledge of how to achieve redis cache, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to achieve redis cache. let's take a look.
1. Use the pagoda panel to build the WeChat server first.
2. Open php Management, click install extension, and install redis extension.
3. After installing the redis extension, open redis Management, and click performance Adjustment to change the port number, redis password and other operations.
4. Log in to the backend of PHP, click site Settings to find the performance optimization in common tools, and enter the performance optimization interface to see whether the redis extension environment already supports WeChat.
5. Open the WeChat code, location: / www/wwwroot/ your site domain name / data/config.php
Modify the code snippet to change mysql to redis
Then add the following code
/ /-- CONFIG REDIS-/ / $config ['setting'] [' redis'] ['server'] =' 127.0.0.1' / / by default, you can also use the cloud repository address (remote) / /-- CONFIG REDIS-- / / $config ['setting'] [' redis'] ['server'] =' 127.0.0.1' / / default local, you can also use the cloud repository address (remote) $config ['setting'] [' redis'] ['port'] = 6379; / / default port $config [' setting'] ['redis'] [' pconnect'] = 1; $config ['setting'] [' redis'] ['auth'] =; / / redis password, default is empty $config [' setting'] ['redis'] [' timeout'] = 1
6. Then log in to the config backend, click site Settings, find the performance optimization in the common tools, and enter the performance optimization interface to see whether the WeChat settings have been enabled. So far, redis has been configured.
7. Next, write the connection code about redis:
/ * redis link * / 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. Then you can use the redis function as much as you like.
This is the end of the article on "how to implement redis caching". Thank you for reading! I believe that everyone has a certain understanding of "how to achieve redis cache" knowledge, if you want to learn more knowledge, welcome to follow the industry information channel.