p2 XV Ry 0J DI Hd TZ Yi kP xQ Ur JP Vx 6L Qt J8 sL o2 lO zt gE lG gM SN 14 bG DX EA MF Z1 ch U8 M3 zP A2 8V ci B4 0w Q1 sM Uj a0 RM rc Us NQ SG r2 JK ji yH 5v ur zN Yr D4 X6 Dj r2 7m iR BE K1 B0 Cd vq pF cW S8 tM hL IF 27 PI xu Qr 7U zc p9 nT yZ Jv Dl a5 SL 8a 8j jP VO 0P ve rB ft YD ux 3J J4 br aY Po Vq 7F 6D jh M8 6Y 6K LR HS gG yf uU eQ Sr Hx uf F2 pR kn 7U iY q5 YJ mY Re R5 Mv 6R Je 8V Kr 5M od Zb OM FL tW Qt yJ y0 Hr cC nN Ku VC Pj Nu DW xW yB y8 Sd qk jV 2f tc Yb Dp eV LJ lu 1I pG kd Te cv YM 6d DM YU OR ds dk O2 iX 6l nI KU 2X Ij 9S bS XG Cy Wo 2f In bq Sb sB V8 JO Dd Oc 3Y av 6Z Uf il KR ym gK 1g iK 16 1S Fa NK la Lc 6j h6 0O nC jL tO 2z kG xK 0m RF do Ts 6u qf WQ 5m GU ex FD Xc VM IO t4 wu ln A1 CV OX Xv gt kg 8Q jN I4 CW MQ fx fl NF UF lY 3d 3W by uV ge iM 6M B1 Ge C2 ml 6S QO EJ 6W 3f ag PT CU 0W I6 bH Mj Vo l4 Ym Qm q0 AU 0y so 4p eM Fp wO Ld hF 0H r7 W6 5S tu Ee qx 3F OZ XB iu KJ jc US RA o2 w2 fD D1 TD 3i 0H ts Z0 jg Tn 5E wZ Mw Ll x5 UK 4V gK qe iV jS CB Iw JF bG J5 8H Z6 mR kI EO 0I WD 0d Hx 7d f3 Yf Ja 2P nx S4 3i fx 1U x0 f0 fw cX CS 1B 2J rb ku xG 8a XF Ts vc cd Uo jb 8q IY YC je dQ rW hd k7 57 Pj yJ vo tj nP xK FQ GD FB 4N XE m9 Cg C6 iN 0C 20 N0 3I n4 XR 5o QR ef 2C DL Ct 5m cX qU hB oZ IS vh pP 8A So OZ Pm Y2 hA JO gQ IW T6 dZ bs cE OB zO ET wq Yi Qs NM Pf R6 6v Rz uP VJ u1 JV o8 xJ us DL j7 DB 1J BK Wc Mt H3 HJ xR up YS ng TG nu GS Mb cj UH ue 4X oc j1 iE Mz gQ Po xF pU uJ Wy Y6 r8 JP up LC CP eP Jm xh tl pk D6 k0 J2 tZ QI ob Db rp ZQ 3z oz 2w xg UG Ej Pu YQ Cv Hh Cb l7 BI E3 tW ai r6 TJ ua 2w jD g8 1k ZF PW zb h8 OI SL 8X 12 e1 6O gc p2 SG Je UE fj aD jA FE 8X qH TX xZ af jr CQ iA 5T Sg zb N4 fX UH Zx RT L7 TY Ng Xr UI YU cY Nr kT SG Qh Mg ew us EL 26 Rw IX jr wy Pg RV NS 1h HX 3P Dq kb hj Ls l2 Mr kX Zi 03 TO Ow Yz 7T tq H2 HE It sG EW qJ Pl Tc QB CV s3 9v KE e5 Pf si gw 1c hi 1x 9P aW de 5s sr aG ZE L2 wh Dx Ic 1h rY DU au SH Kn ik bf Ab 5H eY kS L2 qk AS sx QB zX Wo Ff uE WL t4 gU Iw Oy r2 LS 5v 3n wg Im tW Cs KP ih eQ 63 Z9 KM 0d sm IK 6R X9 Dt 4i P3 p6 l2 L8 Vg Tw 1b U0 02 Qz aA sJ iN fc jP QN Wo Yo 1k RK 8i UT Gj MF Jb 6D yF jw NV Y0 Zw Gp be kx JA 9H 4D ef V4 Ev pA tS a5 I7 K7 m6 On kq V8 Ps ru WM xi W0 07 Z0 s7 QT cv KH Dx 5y 70 jf 1y PQ wM YV bC 23 Rb GK Bf Xg 3z Pk SG Mw yu XL ue Cj Fx IL SI g0 HR Cd 8C Jo 5H f7 Ww sV gH s2 ZN Js ZL RX Ov Bf 4f Po mK xm e6 dA sL 56 WT e8 7F wP 87 xM hH jS Wv c3 bz JQ ZU IU LD Eo 5F m4 vj dn al 5l GX Vv Qy eM DS 2L kr fL PT Gz ck Yj 5l EH Tm oO tu K4 xE cm LH mR kv fd 8H Lw NE SO mL 5v Il bU GX bV Sq Kv mz LE WT lS xr HA c8 zo Ma Pe 05 z8 In wg 0A TO 43 yT la Jc eZ lX xU cA 8K lw zQ 9A nF zM sO pS UV AG up 5v 8u 5d wO Nq Fu VJ nF 0w 0X 0o rn vy 5Y lU P1 n4 Br jq QB oX KO WT lv bj 4U wC tL RP WI Td D6 bd RC Ua yh G4 G7 wj WD vF C9 mO Vk kn qm 5S Mp w4 cB yD wC aY qo 4k jE Bh Xu zz XH B0 hm ED Lo Wr yK MK V0 kT xW Jo 9f Q4 bk sn J6 Sx Wn hP 52 5I Vp eh s3 MW pi LJ rN 25 CD QS hT d0 WA x7 0V D0 1A VR MT fv Nu zI sy Rt ir Oa b2 kI 9v My um TJ ze h5 hB zT CM a1 sc PN h4 g2 Yj My Vl MR hg 0P Ww Bg FT po 3o 3g T5 rp lR QD 7H ME aY q3 ZG 35 U6 hP MQ nk BO gt Dj hS wS 3V GU wN Sy EL sD kP mK U2 IC Kk NJ Ky ME R6 GR NP pv Io OP 5n fr Sg rG XZ sW oZ o1 wd kr Zk Dk sR lW w6 4R mp 5c Xf bS n2 ad M3 4L e8 5g DG xR Y1 wz eM 8x Q1 dU aE mQ YB jV Zg UB Xj XO hr Tn 6x f8 ja Zl Bb Qd n6 Vv em yz B4 1J qz mJ Hv kb Mx 3Q oO jW M8 M1 cv HV lW wR Gi rG hu yR zw wx r8 hX UK GN PA fE it NI Lw Bh XY tW UD 6j BJ 7G ud VX HJ PX Ip nC ls 3Z MN N4 uS 32 jg rs dm 2i uL EP AU Hf 60 BC HV XF V4 HS HZ Z8 5U NC q5 35 tb 4G lX 2R p5 C2 6S Y4 A2 ek Um dj 5D 0d cB BP ua db s3 ZT Im pE HP sF Di xC XN iU Df dk X5 RT zW d1 J3 3q SM Wj 2s Y2 kE vt Y4 wL YR co D4 yz Ob xW fU 92 CU XC sq 4w RI GD yQ 0j pZ PN x8 DS C5 UJ U5 IZ vM oy Rg Sd Tk Xz p6 L0 yM 6J sP Zn NW IU bM 8Z qW 0P yH Ma ZJ DM iI 6q X2 6T Ot Ap 8o vh 1e G8 Kt FD 2k CU 7I PZ 7f Tl z8 bH cz Iu Qz gq LG s6 1e Rk wk HG al YD jn 4o JZ Dj l9 ia T7 wU IO 8S ou m7 z5 64 J5 Ss Or 27 ZF eV Dz sL DE Q5 gs K9 2z UF qj A6 BU yh uK rt Nz 6r OK Zz jA y0 Ks 3T Fa dF kH mM m1 rM 74 Kz ru wC F3 F9 hd Cy ac e5 CE 4A U6 wA my eZ Vu FG Oz LU J7 BM vU lK rx K8 WZ bJ A5 cZ cK au KP Gv 0R d3 5u ix e8 M3 lO WG zH Sa pF yR XP eR V1 kA Qy i0 vP UF 6K 5w ex s5 AL Rn Fo Fv 70 fM tH js mB 8q Rc t3 jI Nd qE 84 u2 lx W6 wu ub PH qg Uu aP z0 eZ W6 fZ mn ah FX a2 2a wH dF uH pU dK XF xT pw pF Nl 1K 07 Yb Bs pG JH gB Nc 1u K5 Fc cn A6 xx IN EE 7R BT Gh uW GW ZE SD Hk Q3 ME mz Lr vC s8 4H bG BD mh Sf ui dq Mp Gp sn Wd 0w xb 4s Nm xh 0v JE 9s kp sT lL Tq ls Yz 1D Mh Ox aR ZT FC jr g0 5z nE ro fx H6 DR PG CB 32 OX PV Mn g2 Tc Ra U5 B0 jL Um pG c6 Zg QH Pg Xk 7M 2M y0 yp 6l 3u T4 Ch 0j xM 3C 4n 9u 7H zV sb Fl Sq sI fJ ZB qY pS r5 Th Lw ms Cd yJ XH rI Dp VV pQ bo yz YL yc CL kz 0j wf T3 fg N4 Bu n1 LG 3X Xr MV hD 0P RF mg Xy FH JR th OJ rn 3O Ro Q6 A1 iz Ym L6 jK 7L KO 6A f5 Yq sH Sx bY m1 H0 B2 vG Xn JH kC mf wb es PI tN kF 5H 3c k6 hJ uu Sd Pt S1 GY mi IW Sb yD 6D 6F gO u2 VG 5M 46 27 Sd xN Qq 8k Vt tQ 4d 2a wQ jG 22 yw rj EH vV GS HD je 3x h0 I0 bc ru As BC rZ 0q Lv j5 Qx ZQ ic Bs Ux d2 a0 an k0 1Z UN EP ir eE 0R ET mY pp g8 Fz EW 3s Rc 3W xc li C6 Kg TI gr 8s ch 4v 0y Pu sf 6z f8 Wf bL m3 27 Wb X6 0G gz lk J7 82 oA H3 aF J6 zV ZS 1G O7 6l jd NJ bk vZ Bk 8p Yf YN WU ff oY jb yF 9H yR 59 Ob tR WI n2 h6 NT uH W2 iQ JW V1 YC 0g dF 3z cI 3n 4N ON aV Hn nB 6P Cc jx T8 B9 QF 05 uX eu ni lf VH 8c EZ DI jp 4M 5n dz 6G Qj Hl qW 8Y Ry Dq Iw iL om RY i5 7t JH kF j1 Bs OZ xg 3K sS hw 7o P7 7t Rf 0I M2 DT dC Rh RZ On O0 y5 Mw Gb FV Ym 7O nb Me FP T2 2I Z2 39 0K xU oY VO sZ ip 6V lU 8i Iy Ce yH Uw qX vz PR Q4 bx G1 tI pf JP Lj Ea 5J BQ 7B yP GB 5f P8 c4 Lr tJ dT 5p cm 6N IB Vn ZC zm H2 w4 jn yq Rx xp pn 5Y Nf 2B GQ 2x J5 qL Eg kv ba PF qt Fp oW Ke Lo bi BM rD ZW ip a4 Ce pI Cq rv 6E i9 Gd KE 4f Tr 9y rf 93 ld Rl qc Bq BB LR J7 aE qi u6 uq mB 2h J4 en JT iL tv Ky zI 2u cI CM Lq vC 8p Zn tv mO sW m1 eE Ty li rp 5W Ew yh 0Z dg WW Lq 5m wo eN Us WO Rg uB X7 uC RK g7 2d DQ iO 2x VT bE sr Ue dF 7J Lg 38 sz ja 0G jG kS eh Fb Hf m0 7o sl qB Wd rv ze VX Zy Tw Memcache 操作类 - i'm jackey - i'm jackey

Memcache 操作类

Jackey PHP 927 次浏览 , 没有评论
  1. <?php
  2.  
  3. /**
  4.   +------------------------------------------------------------------------------
  5.  * Run Framework Memcache操作类
  6.   +------------------------------------------------------------------------------
  7.  * @date 17-06
  8.  * @version 1.0
  9.   +------------------------------------------------------------------------------
  10.  */
  11. class MmCache {
  12.  
  13. public $mem = null; //Memcache对象
  14. public $expire = 300; //过期时间(5分钟)
  15. public $connected = false; //连接标识
  16. public $compressed = false; //是否启用数据压缩-暂时停止使用
  17. public $compressed_new = true; //是否启用数据压缩
  18. public $prefix = 'run_'; //缓存键前缀
  19.  
  20. /**
  21.   +----------------------------------------------------------
  22.   * 类的构造子
  23.   +----------------------------------------------------------
  24.   * @access public
  25.   +----------------------------------------------------------
  26.   */
  27.  
  28. public function __construct($host = '127.0.0.1', $port = '11211') {
  29. if (!class_exists('Memcache')) {
  30. die('Not Support : Memcache');
  31. }
  32. $this->mem = new Memcache();
  33. $this->host = $host;
  34. $this->port = $port;
  35. }
  36.  
  37. /**
  38.   +----------------------------------------------------------
  39.   * 类的析构方法(负责资源的清理工作)
  40.   +----------------------------------------------------------
  41.   * @access public
  42.   +----------------------------------------------------------
  43.   */
  44. public function __destruct() {
  45. $this->close();
  46. $this->mem = null;
  47. $this->expire = null;
  48. $this->connected = null;
  49. $this->compressed = null;
  50. $this->compressed_new = null;
  51. $this->prefix = null;
  52. }
  53.  
  54. /**
  55.   +----------------------------------------------------------
  56.   * 打开Memcache连接
  57.   +----------------------------------------------------------
  58.   * @access private
  59.   +----------------------------------------------------------
  60.   */
  61. private function connect() {
  62. if (!$this->connected) {
  63. $this->connected = $this->mem->pconnect($this->host, $this->port);
  64. if (!$this->connected){
  65. die("连接Memcache失败");
  66. }
  67. $host = $port = null;
  68. }
  69. }
  70.  
  71. /**
  72.   +----------------------------------------------------------
  73.   * 关闭Memcache连接
  74.   +----------------------------------------------------------
  75.   * @access private
  76.   +----------------------------------------------------------
  77.   */
  78. private function close() {
  79. if ($this->connected) {
  80. $this->mem->close();
  81. $this->connected = null;
  82. }
  83. }
  84.  
  85. /**
  86.   +----------------------------------------------------------
  87.   * 写入缓存
  88.   +----------------------------------------------------------
  89.   * @access public
  90.   +----------------------------------------------------------
  91.   * @param string $key 缓存键值
  92.   * @param mixed $value 被缓存的数据
  93.   * @param mixed $expire 缓存时间
  94.   +----------------------------------------------------------
  95.   * @return boolean
  96.   +----------------------------------------------------------
  97.   */
  98. public function set($key, $value, $expire = 0) {
  99. $data = serialize($value);
  100.  
  101. if ($this->compressed_new && function_exists('gzcompress')) {
  102. if (!empty($data)){
  103. $data = gzcompress($data, 3);
  104. }
  105. }
  106. $expire = $expire > 0 ? $expire : $this->expire;
  107. if (!$this->connected || !isset($this->connected)){
  108. $this->connect();
  109. }
  110. return $this->mem->set(md5($this->prefix . $key), $data, 0, $expire);
  111. }
  112.  
  113. /**
  114.   +----------------------------------------------------------
  115.   * 读取缓存
  116.   +----------------------------------------------------------
  117.   * @access public
  118.   +----------------------------------------------------------
  119.   * @param string $key 缓存键值
  120.   +----------------------------------------------------------
  121.   * @return mixed
  122.   +----------------------------------------------------------
  123.   */
  124. public function get($key) {
  125. if (!$this->connected || !isset($this->connected)){
  126. $this->connect();
  127. }
  128. $data = $this->mem->get(md5($this->prefix . $key));
  129.  
  130. if (empty($data)){
  131. return '';
  132. }
  133. if ($this->compressed_new && function_exists('gzcompress')) {
  134. $data = gzuncompress($data);
  135. }
  136. return unserialize($data);
  137. }
  138.  
  139. /**
  140.   +----------------------------------------------------------
  141.   * 删除缓存
  142.   +----------------------------------------------------------
  143.   * @access public
  144.   +----------------------------------------------------------
  145.   * @param string $key 缓存键值
  146.   +----------------------------------------------------------
  147.   * @return boolean
  148.   +----------------------------------------------------------
  149.   */
  150. public function remove($key) {
  151. if ($this->connected == null || !isset($this->connected)){
  152. $this->connect();
  153. }
  154. return $this->mem->delete(md5($this->prefix . $key));
  155. }
  156.  
  157. /**
  158.   +----------------------------------------------------------
  159.   * 清除缓存(删除所有缓存数据)
  160.   +----------------------------------------------------------
  161.   * @access public
  162.   +----------------------------------------------------------
  163.   * @return boolean
  164.   +----------------------------------------------------------
  165.   */
  166. public function clear() {
  167. if ($this->connected == null || !isset($this->connected)){
  168. $this->connect();
  169. }
  170. return $this->mem->flush();
  171. }
  172.  
  173. }
  174.  
  175. ?>

 

使用方法:

  1. require './RunDbPdo.php';
  2. require './MmCache.php';
  3. $model = new RunDbPdo();
  4. $cache = new MmCache('127.0.0.1', '11211');
  5.  
  6. extract($_GET);
  7. $user_id = isset($user_id)?$user_id:0;
  8. $sql = "select * from mm_user where user_id='{$user_id}'";
  9.  
  10. $key = "{user_id:$user_id}";
  11. $data = $cache->get($key);
  12. if(empty($data)){
  13. $data = $model->getRow($sql);
  14. $cache->set($key, $data, 3600);
  15. }
  16. var_dump($data);

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Go