当前位置:网站首页>Simple example of using redis in PHP
Simple example of using redis in PHP
2022-04-23 03:03:00 【Stupid little attendant】
<?php
// header("Content-Type: text/html;charset=utf-8");
try {
$redis = new Redis();
$redisConn = $redis->connect('127.0.0.1', 6379);
} catch (Exception $e) {
$text = $e->getMessage();
// solve PHP The output shows a small black diamond with a question mark
die(iconv("GB2312", "UTF-8", $text));
}
// Connect to database
$host = '127.0.0.1';
$username = 'root';
$pass = '';
$dbname = 'mmw';
$conn = new mysqli($host, $username, $pass, $dbname);
if (!$conn) {
die(' Database connection failed '. $conn->connect_error);
}
// rpush Add a string value from the end of the list
// for ($i = 0; $i < 2; $i++) {
// $redis->rpush('test', $i);
// }
// llen Returns the length of the list
$length = $redis->llen('test');
var_dump($length);
if ($length <= 0) {
die(' No value ');
}
for ($i = 0; $i < $length; $i++) {
// lpop Return and remove the first element of the list
$value = $redis->Lpop('test');
try {
$sql = 'insert into mmw_user (name) values (' . $value . ')';
$result = mysqli_query($conn, $sql);
if ($result && mysqli_affected_rows($conn) > 0) {
echo ' Insert the success ';
} else {
die(' Insert the failure ');
}
} catch (Exception $e) {
die(' Insert the failure ' . $e->getMessage());
}
// Delay 1 Seconds to perform
sleep(1);
}
版权声明
本文为[Stupid little attendant]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220630238536.html
边栏推荐
- tf. keras. layers. MaxPooling? D function
- 腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
- 最通俗易懂的依赖注入与控制反转
- C# 11 对 ref 和 struct 的改进
- TP5 customization in extend directory succeeded and failed. Return information
- Cloud computing learning 1 - openstack cloud computing installation and deployment steps with pictures and texts (Xiandian 2.2)
- PDH optical transceiver 4-way E1 + 4-way 100M Ethernet 4-way 2m optical transceiver FC single fiber 20km rack type
- Some problems encountered in setting Django pure interface, channel and MySQL on the pagoda panel
- Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (10)
- Navicat premium import SQL file
猜你喜欢
随机推荐
Xamarin效果第二十二篇之录音效果
FileNotFoundError: [Errno 2] No such file or directory
How to deploy a website with only a server and no domain name?
C# 11 的这个新特性,我愿称之最强!
VirtualBox virtual machine (Oracle VM)
Introduction to ACM [TSP problem]
Processes and threads
C# WPF UI框架MahApps切换主题
腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
《信息系统项目管理师总结》第七章 项目沟通管理
.Net Core 限流控制-AspNetCoreRateLimit
《信息系统项目管理师总结》第五章 项目质量管理
Basic SQL (VIII) data update operation practice
Linux redis - redis database caching service
Deep q-network (dqn)
In redis cluster, the master node fails, and the IP changes after the master-slave switch. The client does not need to deal with it
Redis data server / database / cache (2022)
AOT和单文件发布对程序性能的影响
TP5 multi conditional where query (using PHP variables)
Publish to NPM?