- <?php
- /**
- * redis添加数据
- * Enter description here ...
- * @author Administrator
- *
- */
- class AddAction extends Action{
- /**
- * list类型
- * Enter description here ...
- */
- public function lists(){
- $Redis=new RedisModel("list11");
- //一次只能推送一条
- echo $Redis->add("ceiba");
- }
- /**
- * 字符串类型
- * Enter description here ...
- */
- public function string(){
- $Redis=new RedisModel();
- $data=array(
- "str1"=>"ceiba", //一个key,对应一个值
- "str2"=>"李开湧",
- "str3"=>"李明",
- );
- echo $Redis->type("string")->add($data);
- }
- /**
- * HASH类型
- * Enter description here ...
- */
- public function hash(){
- $Redis=new RedisModel("user:1");
- $data=array(
- "field1"=>"ceiba", //一个key,对应一个值
- "field2"=>"李开湧",
- "field3"=>"李明",
- );
- //支持批量添加
- echo $Redis->type("hash")->add($data);
- }
- /**
- * 集合类型
- * Enter description here ...
- */
- public function sets(){
- $Redis=new RedisModel("sets:1");
- //一次只能推送一条
- echo $Redis->type("sets")->add("ceiba");
- }
- /**
- * 有序集合
- * Enter description here ...
- */
- public function zset(){
- $Redis=new RedisModel("zset:1");
- //支持批量添加
- $data=array(
- //排序=>值
- "10"=>"ceiba",
- "11"=>"李开湧",
- "12"=>"李明"
- );
- echo $Redis->type("zset")->add($data);
- }
- }
- ?>
- <?php
- /**
- * redis添加数据
- * Enter description here ...
- * @author Administrator
- *
- */
- class AddAction extends Action{
- /**
- * list类型
- * Enter description here ...
- */
- public function lists(){
- $Redis=new RedisModel("list11");
- //一次只能推送一条
- echo $Redis->add("ceiba");
- }
- /**
- * 字符串类型
- * Enter description here ...
- */
- public function string(){
- $Redis=new RedisModel();
- $data=array(
- "str1"=>"ceiba", //一个key,对应一个值
- "str2"=>"李开湧",
- "str3"=>"李明",
- );
- echo $Redis->type("string")->add($data);
- }
- /**
- * HASH类型
- * Enter description here ...
- */
- public function hash(){
- $Redis=new RedisModel("user:1");
- $data=array(
- "field1"=>"ceiba", //一个key,对应一个值
- "field2"=>"李开湧",
- "field3"=>"李明",
- );
- //支持批量添加
- echo $Redis->type("hash")->add($data);
- }
- /**
- * 集合类型
- * Enter description here ...
- */
- public function sets(){
- $Redis=new RedisModel("sets:1");
- //一次只能推送一条
- echo $Redis->type("sets")->add("ceiba");
- }
- /**
- * 有序集合
- * Enter description here ...
- */
- public function zset(){
- $Redis=new RedisModel("zset:1");
- //支持批量添加
- $data=array(
- //排序=>值
- "10"=>"ceiba",
- "11"=>"李开湧",
- "12"=>"李明"
- );
- echo $Redis->type("zset")->add($data);
- }
- }
- ?>
2、查询数据
- <?php
- // redis查询数据
- class IndexAction extends Action {
- public function page(){
- $this->display();
- }
- /**
- * 列表类型,默认类型
- * Enter description here ...
- */
- public function lists(){
- //dump(C("REDIS_HOST"));
- $Redis=new RedisModel("list1");
- $field=array(
- "nmae","age","pro"
- );
- $data=$Redis->field($field)->select();
- dump($data);
- //获得队列中的记录总数
- $count=$Redis->count();
- dump($count);
- }
- /**
- * 字符串类型
- * Enter description here ...
- */
- public function string(){
- $Redis=new RedisModel();
- //field 表示每个key名称
- $rows=$Redis->type("string")->field(array("str1","str2"))->select();
- dump($rows);
- }
- /**
- * HASH类型
- * Enter description here ...
- */
- public function hash(){
- $Redis=new RedisModel("h9");
- //默认显示所有HASH字段,可以通过field连惯操作限制
- $rows=$Redis->type("hash")->field(array("field1"))->select();
- dump($rows);
- //统计总记录
- $count=$Redis->type("hash")->count();
- dump($count);
- }
- /**
- * 集合类型
- * Enter description here ...
- */
- public function sets(){
- $Redis=new RedisModel();
- $arr=array(
- "s3","s4"
- );
- $rows=$Redis->type("sets")->field($arr)->where("sinterstore")->select();//求交集
- dump($rows);
- $rows=$Redis->type("sets")->field($arr)->where("sunion")->select();//求并集
- dump($rows);
- $rows=$Redis->type("sets")->field($arr)->where("sdiff")->select();//求差集
- dump($rows);
- $Redis=new RedisModel("s3");
- $rows=$Redis->type("sets")->select(); //返回单个集合列表中的所有成员
- dump($rows);
- //统计记录
- $Redis=new RedisModel("s3");
- $count=$Redis->type("sets")->count();
- dump($count);
- }
- /**
- * 有序集合
- * Enter description here ...
- */
- public function zset(){
- $Redis=new RedisModel("z2");
- //默认显示0到20
- $data=$Redis->type("zset")->limit("0,-1")->select();
- dump($data);
- //使用zRevRange显示数据,数组第2个参数为true时显示排序号
- $data=$Redis->type("zset")->limit("0,-1")->order(array("zRevRange",true))->select();
- dump($data);
- //不设置limit时,将统计所有记录
- $count=$Redis->type("zset")->limit("0,1")->count();
- dump($count);
-
- }
- }
- <?php
- // redis查询数据
- class IndexAction extends Action {
- public function page(){
- $this->display();
- }
- /**
- * 列表类型,默认类型
- * Enter description here ...
- */
- public function lists(){
- //dump(C("REDIS_HOST"));
- $Redis=new RedisModel("list1");
- $field=array(
- "nmae","age","pro"
- );
- $data=$Redis->field($field)->select();
- dump($data);
- //获得队列中的记录总数
- $count=$Redis->count();
- dump($count);
- }
- /**
- * 字符串类型
- * Enter description here ...
- */
- public function string(){
- $Redis=new RedisModel();
- //field 表示每个key名称
- $rows=$Redis->type("string")->field(array("str1","str2"))->select();
- dump($rows);
- }
- /**
- * HASH类型
- * Enter description here ...
- */
- public function hash(){
- $Redis=new RedisModel("h9");
- //默认显示所有HASH字段,可以通过field连惯操作限制
- $rows=$Redis->type("hash")->field(array("field1"))->select();
- dump($rows);
- //统计总记录
- $count=$Redis->type("hash")->count();
- dump($count);
- }
- /**
- * 集合类型
- * Enter description here ...
- */
- public function sets(){
- $Redis=new RedisModel();
- $arr=array(
- "s3","s4"
- );
- $rows=$Redis->type("sets")->field($arr)->where("sinterstore")->select();//求交集
- dump($rows);
- $rows=$Redis->type("sets")->field($arr)->where("sunion")->select();//求并集
- dump($rows);
- $rows=$Redis->type("sets")->field($arr)->where("sdiff")->select();//求差集
- dump($rows);
- $Redis=new RedisModel("s3");
- $rows=$Redis->type("sets")->select(); //返回单个集合列表中的所有成员
- dump($rows);
- //统计记录
- $Redis=new RedisModel("s3");
- $count=$Redis->type("sets")->count();
- dump($count);
- }
- /**
- * 有序集合
- * Enter description here ...
- */
- public function zset(){
- $Redis=new RedisModel("z2");
- //默认显示0到20
- $data=$Redis->type("zset")->limit("0,-1")->select();
- dump($data);
- //使用zRevRange显示数据,数组第2个参数为true时显示排序号
- $data=$Redis->type("zset")->limit("0,-1")->order(array("zRevRange",true))->select();
- dump($data);
- //不设置limit时,将统计所有记录
- $count=$Redis->type("zset")->limit("0,1")->count();
- dump($count);
-
- }
- }
3、删除数据
- <?php
- /**
- * Redis删除数据
- * Enter description here ...
- * @author Administrator
- *
- */
- class DeleteAction extends Action{
- /**
- * list类型
- * Enter description here ...
- */
- public function lists(){
- $Redis=new RedisModel("mylist");
- //根据索引号,删除指定的list元素
- echo $Redis->where(3)->delete();
- //ltrim区间批量删除,保留4~5之间的记录
- echo $Redis->type("list")->where(array("4","5"))->delete("ltrim");
- //lpop单条顺序弹出
- echo $Redis->type("list")->delete("lpop");
-
- }
- /**
- * 字符串类型
- * Enter description here ...
- */
- public function string(){
- $Redis=new RedisModel();
- //直接删除key,这各方式适用于所有数据类型
- echo $Redis->type("string")->field(array("str1","str2"))->delete();
- }
- /**
- * HASH类型
- * Enter description here ...
- */
- public function hash(){
- $Redis=new RedisModel("user:1");
- //删除指定hash中的指定字段(field),不支持批量删除
- echo $Redis->type("hash")->where("field1")->delete();
-
- }
- /**
- * 集合类型
- * Enter description here ...
- */
- public function sets(){
- $Redis=new RedisModel("s1");
- //删除sets:1集合中名为age的value
- echo $Redis->type("sets")->where("age")->delete();
- }
- /**
- * 有序集合
- * Enter description here ...
- */
- public function zset(){
- $Redis=new RedisModel("z1");
- //根据集合元素value进行删除
- echo $Redis->type("zset")->where("two")->delete();
- //根据排序号进行区间批量删除,保留2~3之间的记录
- echo $Redis->type("zset")->where(array("1","4"))->delete("zremRangeByScore");
- //根据索引号进行区间批量删除,保留2~3之间的记录
- echo $Redis->type("zset")->where(array("1","3"))->delete("zRemRangeByRank");
- }
- }
- ?>
- <?php
- /**
- * Redis删除数据
- * Enter description here ...
- * @author Administrator
- *
- */
- class DeleteAction extends Action{
- /**
- * list类型
- * Enter description here ...
- */
- public function lists(){
- $Redis=new RedisModel("mylist");
- //根据索引号,删除指定的list元素
- echo $Redis->where(3)->delete();
- //ltrim区间批量删除,保留4~5之间的记录
- echo $Redis->type("list")->where(array("4","5"))->delete("ltrim");
- //lpop单条顺序弹出
- echo $Redis->type("list")->delete("lpop");
-
- }
- /**
- * 字符串类型
- * Enter description here ...
- */
- public function string(){
- $Redis=new RedisModel();
- //直接删除key,这各方式适用于所有数据类型
- echo $Redis->type("string")->field(array("str1","str2"))->delete();
- }
- /**
- * HASH类型
- * Enter description here ...
- */
- public function hash(){
- $Redis=new RedisModel("user:1");
- //删除指定hash中的指定字段(field),不支持批量删除
- echo $Redis->type("hash")->where("field1")->delete();
-
- }
- /**
- * 集合类型
- * Enter description here ...
- */
- public function sets(){
- $Redis=new RedisModel("s1");
- //删除sets:1集合中名为age的value
- echo $Redis->type("sets")->where("age")->delete();
- }
- /**
- * 有序集合
- * Enter description here ...
- */
- public function zset(){
- $Redis=new RedisModel("z1");
- //根据集合元素value进行删除
- echo $Redis->type("zset")->where("two")->delete();
- //根据排序号进行区间批量删除,保留2~3之间的记录
- echo $Redis->type("zset")->where(array("1","4"))->delete("zremRangeByScore");
- //根据索引号进行区间批量删除,保留2~3之间的记录
- echo $Redis->type("zset")->where(array("1","3"))->delete("zRemRangeByRank");
- }
- }
- ?>
|