国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

? ??? ?? PHP ???? PHP? redies? ???? ???? ?????.

PHP? redies? ???? ???? ?????.

Jul 25, 2016 am 08:43 AM

  1. /**
  2. * Redis ??, ???/???? ?? ???? ??
  3. *
  4. * @author jackluo
  5. */
  6. class RedisCluster{
  7. // M/S ??-?? ?? ?? Cluster Scheme
  8. private $_isUseCluster = false;
  9. // ???? ?? ??
  10. private $_sn = 0
  11. // ?? ?? ??
  12. private $_linkHandle = array (
  13. 'master'=>null,// ??? ???? ?????
  14. 'slave'=>array(),// ?? ????? ?? ? ????
  15. ); *
  16. * ???
  17. *
  18. * @param boolean $isUseCluster M/S ?? ?? ??
  19. */
  20. ?? ?? __construct($isUseCluster=false){
  21. $this->_isUseCluster = $isUseCluster
  22. }
  23. /**
  24. * ??? ?????. ??: ????? ???? ??? ?? ? ??? ????? ???? ???? ????.
  25. *
  26. * @param array $config Redis ?? ??
  27. * @param boolean $isMaster ?? ??? ??? ??? ???? ??
  28. * @return boolean
  29. * /
  30. ?? ?? connect($config=array('host'=>'127.0.0.1','port'=>6379), $isMaster=true){
  31. // ?? ??
  32. if (!isset($config['port'])){
  33. $config['port'] = 6379;
  34. }
  35. // ??? ?? ??
  36. if($isMaster){
  37. $this->_linkHandle['master'] = new Redis()
  38. $ret = $this->_linkHandle['master']->pconnect($config['host'],$ config ['port']);
  39. }else{
  40. // ?? ???? ??
  41. $this->_linkHandle['slave'][$this->_sn] = new Redis()
  42. $ret = $this->_linkHandle['slave'][$this->_sn]->pconnect($config['host'],$config['port'])
  43. $ this->_sn;
  44. }
  45. return $ret
  46. }
  47. /**
  48. * ?? ??
  49. *
  50. * @param int $flag ?? ?? 0: ??? ?? 1: ???? ?? 2: ?? ??
  51. * @return boolean
  52. */
  53. ?? ?? close($flag=2){
  54. switch($flag){
  55. // ??? ??
  56. ?? 0:
  57. $this->getRedis()->close()
  58. break
  59. // ???? ??;
  60. ?? 1:
  61. for($i=0; $i<$this->_sn; $i){
  62. $this->_linkHandle['slave'][$i] -> ;close();
  63. }
  64. break;
  65. // ?? ??
  66. ?? 1:
  67. $this->getRedis()->close(); $i=0; $i<$this->_sn; $i){
  68. $this->_linkHandle['slave'][$i]->close()
  69. }
  70. break;
  71. }
  72. true? ?????.
  73. }
  74. /**
  75. * ?? Redis ??? ???? ? ?? ??? ??? ? ????.
  76. *
  77. * @param boolean $isMaster ?? ??? ?????. true: ???? ?????. false: ????? ?????.
  78. * @param boolean $ slaveOne ??? ???? ?? true: ?? ???? ??? ???? ??? ?????. false: ?? ???? ??? ?????.
  79. * @return redis ??
  80. */
  81. ?? ?? getRedis($isMaster=true,$slaveOne=true) ??> // ???? ??
  82. if($isMaster){
  83. return $this->_linkHandle['master']
  84. }else{
  85. return $this- > _getSlaveRedis() : $this->_linkHandle['slave'];
  86. }
  87. }
  88. /**
  89. * ?? ??
  90. *
  91. * @param string $key ?? ?? KEY
  92. * @param string $value ?? ?
  93. * @param int $expire ?? ??, 0: ?? ??? ?? ??
  94. */
  95. ?? ?? ??($key, $value , $expire=0){
  96. // ?? ??? ???? ??
  97. if($expire == 0){
  98. $ret = $this->getRedis()->set($key , $value );
  99. }else{
  100. $ret = $this->getRedis()->setex($key, $expire, $value)
  101. }
  102. return $ret ; > }
  103. /**
  104. * ?? ??
  105. *
  106. * @param string $key ?? KEY, ? ?? ?? $key ???? ?? = array('key1','key2')
  107. * @return string || boolean ?? ? false? ????, ?? ?
  108. ???? ?????.*/
  109. public function get($key){
  110. // ?? ?? ??? ???? ??
  111. $func = is_array($ key) ? 'mGet' : 'get';
  112. // M/S? ???? ????.
  113. if(! $this->_isUseCluster){
  114. return $this->getRedis()-> ; {$func}($key)
  115. }
  116. // 使用了 M/S
  117. return $this->_getSlaveRedis()->{$func}($key);
  118. }
  119. /*
  120. // 魔術(shù)函數(shù)
  121. public function __call($name,$arguments){
  122. return call_user_func($name,$arguments);
  123. }
  124. */
  125. /**
  126. * 條件形式設(shè)定緩存,如果key 不存時(shí)就設(shè)置,存在時(shí)設(shè)定失敗
  127. *
  128. * @param string $key 緩存KEY
  129. * @param string $value 快取值
  130. * @return boolean
  131. */
  132. public function setnx($key, $value){
  133. return $this->getRedis()->setnx ($鍵,$值);
  134. }
  135. /**
  136. * 刪除快取
  137. *
  138. * @param string || array $key 快取KEY,支援單一健:"key1" 或多個(gè)健:array('key1','key2')
  139. * @return int 刪除的健的數(shù)量
  140. */
  141. public function remove($key){
  142. // $key =>; “區(qū)域1”|| array('key1','key2')
  143. return $this->getRedis()->delete($key);
  144. }
  145. /**
  146. * 值加上操作,類似$i ,如果key 不存在時(shí)自動(dòng)設(shè)定為0 後進(jìn)行加加操作
  147. *
  148. * @param string $key 快取KEY
  149. * @param int $ default 操作時(shí)的預(yù)設(shè)值
  150. * @return int 操作後的值
  151. */
  152. public function incr($key,$default=1){
  153. if($default == 1){
  154. return $this->getRedis()->incr($key);
  155. }else{
  156. return $this->getRedis()->incrBy($key, $default);
  157. }
  158. }
  159. /**
  160. * 值減減操作,類似--$i ,如果key 不存在時(shí)自動(dòng)設(shè)定為0 後進(jìn)行減減操作
  161. *
  162. * @param string $key 快取KEY
  163. * @param int $default 操作時(shí)的預(yù)設(shè)值
  164. * @return int 操作後的值
  165. */
  166. public function decr($key,$default=1){
  167. if($default == 1){
  168. return $this->getRedis()->decr($key);
  169. }else{
  170. return $this->getRedis()->decrBy($key, $default);
  171. }
  172. }
  173. /**
  174. * 添空目前資料庫(kù)
  175. *
  176. * @return boolean
  177. */
  178. public function clear(){
  179. return $this->getRedis()->flushDB();
  180. }
  181. /* =======================以下導(dǎo)管方法============ == == === */
  182. /**
  183. * 隨機(jī) HASH 得到 Redis Slave 伺服器句柄
  184. *
  185. * @return redis object
  186. */
  187. private function _getSlaveRedis(){
  188. // 就一個(gè)從機(jī)直接回傳
  189. if($this -> ; _sn 回傳 $this->_linkHandle['slave'][0];
  190. }
  191. // 隨機(jī)雜湊得到 Slave 的句柄
  192. $hash = $this->_hashId(mt_rand(), $this->_sn);
  193. return $this->_linkHandle['slave'][$hash];
  194. }
  195. /**
  196. * 根據(jù)ID得到 hash 後 0~m-1 之間的值
  197. *
  198. * @param string $id
  199. * @param int $m
  200. * @return int
  201. */
  202. private function _hashId($id,$m=10)
  203. {
  204. // 把字串K轉(zhuǎn)換成0~ m-1 之間的一個(gè)值作為對(duì)應(yīng)記錄的雜湊位址
  205. $k = md5($id);
  206. $l = strlen($k);
  207. $b = bin2hex($k);
  208. $h = 0;
  209. for($i=0;$i {
  210. //相加模式HASH
  211. $h = substr($b,$i*2,2) ;
  212. }
  213. $hash = ($h*1)%$m;
  214. 回傳 $hash;
  215. }
  216. /**
  217. * lpush
  218. */
  219. public function lpush($key,$value){
  220. return $this->getRedis()->lpush($鍵, $值);
  221. }
  222. /**
  223. * 加 lpop
  224. */
  225. public function lpop($key){
  226. return $this->getRedis()->lpop($key){
  227. return $this->getRedis()->lpop($key );
  228. }
  229. /**
  230. * 範(fàn)圍
  231. */
  232. public function lrange($key,$start,$end){
  233. return $this->getRedis()->lrange($鍵,$開(kāi)始,$結(jié)束);
  234. }
  235. /**
  236. * 設(shè)定哈希操作
  237. */
  238. public function hset($name,$key,$value){
  239. if(is_array ($value)){
  240. 回傳$this->getRedis()->hset($name,$key,serialize($value));
  241. }
  242. return $this->getRedis()- >hset($name,$key,$value);
  243. }
  244. /**
  245. * 取得雜湊操作
  246. */
  247. public function hget($name,$key = null,$serialize=true){
  248. if($key){
  249. $row = $this->getRedis()->hget($name,$key);
  250. if($row && $serialize){
  251. unserialize($行);
  252. }
  253. 回傳$行}
  254. return $this->getRedis()->hgetAll($name);
  255. }
  256. /**
  257. * ?? ?? ??
  258. */
  259. ?? ?? hdel($name,$key = null){
  260. if($key){
  261. return $this- >getRedis()->hdel($name,$key);
  262. }
  263. return $this->getRedis()->hdel($name);
  264. }
  265. /**
  266. * ?? ??
  267. */
  268. ?? ?? multi(){
  269. return $this->getRedis()->multi();
  270. }
  271. /**
  272. * ?? ???
  273. */
  274. ?? ?? exec(){
  275. return $this->getRedis()->exec();
  276. }
  277. }// ?? ??
  278. // ================= ??? ?? == ===============
  279. // 只有一臺(tái) Redis ??
  280. $redis = new RedisCluster();
  281. $redis->connect(array('host'=>'127.0.0.1','port'=>6379));
  282. //*
  283. $cron_id = 10001;
  284. $CRON_KEY = 'CRON_LIST'; //
  285. $PHONE_KEY = 'PHONE_LIST:'.$cron_id;//
  286. //cron ??
  287. $cron = $redis->hget($CRON_KEY,$cron_id);
  288. if(empty($cron)){
  289. $cron = array('id'=>10,'name'=>'jackluo');//mysql ???
  290. $ redis->hset($CRON_KEY,$cron_id,$cron); // redis ??
  291. }
  292. //?? ??
  293. $phone_list = $redis->lrange($PHONE_KEY,0,-1);
  294. print_r($phone_list);
  295. if(empty($phone_list)){
  296. $phone_list =explode(',','13228191831,18608041585'); //mysql ???
  297. //?? ??
  298. if($phone_list){
  299. $redis->multi();
  300. foreach ($phone_list? $phone??) {
  301. $redis->lpush($PHONE_KEY,$phone);
  302. }
  303. $redis->exec();
  304. }
  305. }
  306. print_r($phone_list);
  307. /*$list = $redis->hget($cron_list,);
  308. var_dump($list);*/
  309. //*/
  310. //$redis->set('id',35);
  311. /*
  312. $redis->lpush('test','1111');
  313. $redis->lpush('test','2222');
  314. $redis->lpush('test','3333');
  315. $list = $redis->lrange('test',0,-1);
  316. print_r($list);
  317. $lpop = $redis->lpop('???');
  318. print_r($lpop);
  319. $lpop = $redis->lpop('???');
  320. print_r($lpop);
  321. $lpop = $redis->lpop('???');
  322. print_r($lpop);
  323. */
  324. // var_dump($redis->get('id'));
復(fù)代碼

PHP, ???


? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1601
29
PHP ????
1502
276
???
PHP ?? ??? ??????? PHP ?? ??? ??????? Jul 17, 2025 am 04:16 AM

PHP ?? ??? ?? ???? ?? ? ????? ??? ?????. 1. ?? ??? ??? ??? ??? ? ? ??? ??? ??? ?? ?? ??? ???? ???????. 2. ?? ??? ???? ???? ? ?? ????? ?? ?? ?? ??? ?????. 3. $ _get ? $ _post? ?? Hyperglobal ??? ?? ???? ?? ??? ? ??? ??? ??????? ???????. 4. ?? ?? ?? ???? ?? ?? ?? ??? ?????? ?? ??? ??? ?? ??? ???????. ??? ??? ????? ??? ??? ?? ???? ????? ? ??? ? ? ????.

PHP?? ?? ???? ???? ???? ??? ?????? PHP?? ?? ???? ???? ???? ??? ?????? Jul 08, 2025 am 02:37 AM

PHP ?? ???? ???? ????? ?? ? ??? ???? ?? ?? ? ??? ???? ?? ??? ?????? ??? ??? ? ? ???????. 1. ??? ?? CSRF? ???? ?? ??? ??? ???? ?????? ??? ???? FINFO_FILE? ?? ?? MIME ??? ?????. 2. ??? ??? ??? ???? ??? ?? ??? ?? ? WEB ????? ??? ???? ??????. 3. PHP ?? ??? ?? ? ?? ???? NGINX/APACHE? ??? ????? ?? ???? ?????. 4. GD ?????? ??? ? ?? ???? ??? ?? ??? ?? ????.

PHP?? ?? ?? PHP?? ?? ?? Jul 18, 2025 am 04:57 AM

PHP ?? ???? ? ?? ???? ??? ????. 1. // ?? #? ???? ? ?? ??? ???? // ???? ?? ????. 2. ?? /.../ ?? ?? ?? ??? ????? ?? ? ?? ??? ?? ? ? ????. 3. ?? ?? ?? / if () {} /? ?? ?? ??? ????? ??? ?? ?? ?? ??? ???? ????? ???? ??? ?? ???? ???? ??? ? ??? ??????.

PHP?? ???? ??? ?????? PHP?? ???? ??? ?????? Jul 11, 2025 am 03:12 AM

Ageneratorinphpisamemory- ???? Way-Erate-Overgedatasetsetsbaluesoneatimeatimeatimeatimallatonce.1.generatorsuseTheyieldKeywordTocroadtOpvaluesondemand, RetingMemoryUsage.2

PHP ?? ?? ? PHP ?? ?? ? Jul 18, 2025 am 04:51 AM

PHP ??? ???? ??? ??? ??? ????? ????. ??? ????? ?? ???? ??? "?? ? ?"??? "?"? ???????. 1. ??? ? ??? ??? DocBlock (/*/)? ?? ?? ??? ???? ??? ? ?? ???? ??????. 2. JS ??? ???? ?? ???? ??? ?? ??? ??? ?????. 3. ??? ?? ?? ?? ??? ???? ????? ????? ???? ?? ????? ???? ? ??????. 4. Todo ? Fixme? ????? ???? ? ? ??? ??? ???? ?? ?? ? ??? ???????. ??? ???? ?? ??? ??? ?? ?? ?? ???? ???? ? ????.

?? PHP : ??? ??? ?? PHP : ??? ??? Jul 18, 2025 am 04:54 AM

tolearnpheffectical, startBysetTupaloCalserErverEnmentUsingToolslikexamppandacodeeditor -likevscode.1) installxamppforapache, mysql, andphp.2) useacodeeditorforsyntaxsupport.3)) 3) testimplephpfile.next, withpluclucincludechlucincluclucludechluclucled

?? PHP ?? ??? ?? PHP ?? ??? Jul 18, 2025 am 04:52 AM

toinstallphpquickly, usexampponwindowsorhomebrewonmacos.1. ??, downloadandinstallxAmpp, selectComponents, startApache ? placefilesinhtdocs.2

PHP?? ??? ? ???? ??? ????? ?? PHP?? ??? ? ???? ??? ????? ?? Jul 12, 2025 am 03:15 AM

PHP??? ???? ??? ?? ?? ????? ???? ??? ?? ??? ??? ?? ? ??? ??? ???? ?????. ???? 0?? ???? ?? ??? ???? ? ?? ???? ?? ?? ? ? ????. MB_SUBSTR? ?? ??? ??? ???????. ? : $ str = "hello"; echo $ str [0]; ?? H; ??? MB_SUBSTR ($ str, 1,1)? ?? ??? ??? ??? ??????. ?? ???????? ???? ??? ???? ?? ???? ?? ?? ???? ?????? ??? ????? ?? ??? ?? ??? ???? ???? ?? ????.

See all articles