In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail the examples of the use of Redis in Lumen. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
1. Install extension
Two extensions must be installed to use redis
Composer require predis/predis composer require illuminate/redis
(PS: officially, it is required to install two installed versions: predis/predis (~ 1.0) and illuminate/redis (5.2.*). Because these two versions are currently installed, you do not add the version number when using compose. If you find that you cannot use it after installation, please add the version number when executing composer)
two。 Introduction of redis support
To introduce the extension of redis into the directory bootstrap/app.php
$app- > register (Illuminate\ Redis\ RedisServiceProvider::class)
3. Enable redis helper function
Lumen is a little different from Laravel. The default 'Facades'' and 'Eloquent' are not enabled. If you want to use redis in laravel, just open the $app- > withFacades () and $app- > withEloquent () annotations of' Facades' and 'Eloquent' in the file bootstrap/app.php.
4. Configure redis server parameters
The default system is the redis configuration file in the called .env, but these parameters are generally not available after installation. You can check the file path vendor/laravel/lumen-framework/config/database.php to see what parameters need to be configured. For example, my .env file needs to be configured.
REDIS_HOST=192.168.1.41REDIS_PORT=7000REDIS_PASSWORD=123456
5. Use redis
The first step is to introduce classes within the controller that uses redis. Use Illuminate\ Support\ Facades\ Redis
Then you can use the redis function directly.
Redis::setex ('site_name', 10,' Lumen's redis'); return Redis::get ('site_name')
6. The second way to use redis
You can also call redis using the helper function Cache
The first step is to introduce the Cache class into the controller that uses redis. Illuminate\ Support\ Facades\ Cache
Then you can use the redis function directly.
Cache::store ('redis')-> put (' site_name', 'Lumen Test', 10); return Cache::store ('redis')-> get (' site_name'); this is the end of this article on "examples of Lumen using Redis". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.