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

php操作redis的两个个小脚本

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 19:47:371624browse

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(); #关闭连接
?>

 第二个脚本 设置几个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(); #关闭连接
?>

  

 

Statement:
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