Home > php教程 > php手册 > php操作redis的两个个小脚本

php操作redis的两个个小脚本

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:47:37
Original
1615 people have browsed it

redis这东西,查询起来没有mysql那么方便,只能自己写脚本了。下面是工作中写的两个小脚本 第一个脚本,查找有lottery|的键,将他们全部删除|打印出来 ?php$redis = new Redis(); #实例化redis类$redis-connect('127.0.0.1'); #连接服务器$m = $redis-keys('

redis这东西,查询起来没有mysql那么方便,只能自己写脚本了。下面是工作中写的两个小脚本

第一个脚本,查找有lottery|的键,将他们全部删除|打印出来

<?php $redis = new Redis(); #实例化redis类
$redis->connect('127.0.0.1'); #连接服务器
$m = $redis->keys('lottery|*');
print_r($m);
foreach ($m as $key=>$value){
//$redis->del($value);
}
$redis->close(); #关闭连接
?>
Copy after login

 第二个脚本 设置几个key value值,并且打印出来

<?php $redis = new Redis(); #实例化redis类
$redis->connect('127.0.0.1'); #连接服务器
//给出用户id集合,活动id,资格id即可
for($i=1;$iset('lottery|7|cust_id:'.$i.'|grant',27);
}
for ($i=1;$iget('lottery|7|cust_id:'.$i.'|grant');
	echo $tmp;
	echo PHP_EOL;
}
$redis->close(); #关闭连接
?>
Copy after login

  

 

Related labels:
source:php.cn
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 Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template