单例模式 Redis
来源:互联网 发布:灵界室友网络剧百度云 编辑:程序博客网 时间:2024/05/18 18:03
<?php//购物车单例模式class CartSingleton{ //三私一公 //定义一个静态的私变量 static private $_instance=null; private $redis = null; //私有的构造方法 private final function __construct(){ //实例化 $this->redis = new Redis(); $this->redis->connect('127.0.0.1',6379); } //私有的克隆方法 private function __clone(){ } //公有的静态方法 static public function getInstance(){ if(!(self::$_instance instanceof self)){ self::$_instance = new CartSingleton(); } return self::$_instance; } //加入购物车 public function addCart($userId,$gid,$gname){ //hash键名 $hashKey = "user_".$userId; //键名 $key = $gid."_".$gname; //加入 //return $gname; return $this->redis->hIncrBy($hashKey,$key,1); } //购物车列表 public function cartList($userId){ $hashKey = "user_".$userId; //查询 return $this->redis->hGetAll($hashKey); } //清空原有的数据 public function dell($userId,$gid,$gname){ return $this->redis->flushAll(); } //购物车单删 public function cartDel($userId,$gid,$gname){ $hashKey = "user_".$userId; $key = $gid."_".$gname; //删除 return $this->redis->hDel($hashKey,$key); } //清空购物车 public function delall($userId){ $hashKey = "user_".$userId; return $this->redis->del($hashKey); }}
0 0
- 单例模式 Redis
- php redis 单例模式
- python连接redis单例模式
- thinkphp的redis主从分布式的单例模式
- 单例、单例模式
- php多进程单例模式下的 MySQL及Redis连接错误修复
- 简单的PHP redis 单例模式,(基本可以拿过去复制)
- redis单例、主从模式、sentinel以及集群的配置方式及优缺点对比
- 单例模式-多线程单例模式
- 单件模式(单例模式)
- 设计模式之PHP项目应用——单例模式设计Memcache和Redis操作类
- spring配置单Redis,Sentinel 哨兵模式,Redis Cluster集群,Redis Sharding集群
- 设计模式------单例模式
- 设计模式------单例模式
- 设计模式-单例模式
- 设计模式 - 单例模式
- 设计模式---单例模式
- 设计模式---单例模式
- 1019. 数字黑洞 (20)/PAT/YHF/2016.11.21
- 非深户社保满一年走生育险流程。
- C语言中system()执行cmd命令打开关闭程序
- Java多线程中join方法的理解
- 设计模式之策略模式
- 单例模式 Redis
- 自定义相机、相册(相册篇)
- iOS开发信任SSL证书和自签名证书实现HTTPS
- 【Android Meditation】二次封装
- wincecabmanager制作cab包以及解压cab包可以查看详细信息(包含的文件等)
- 【32页PPT】读懂基础机器学习算法
- undefined与null的总结
- SNV自动定时更新
- Seaborn-05-Pairplot多变量图