TestRedis.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php declare(strict_types=0);
  2. use PHPUnit\Framework\TestCase;
  3. define('APP_ID', 'test');
  4. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  5. require_once(BASE_ROOT_PATH . '/global.php');
  6. require_once(BASE_CORE_PATH . '/lrlz.php');
  7. require_once(BASE_ROOT_PATH . '/fooder.php');
  8. require_once (BASE_ROOT_PATH . '/helper/util_helper.php');
  9. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  10. function sub_callback($redis, $chan, $msg)
  11. {
  12. switch($chan) {
  13. case 'chan-1':
  14. print "get $msg from $chan\n";
  15. break;
  16. case 'chan-2':
  17. print "get $msg FROM $chan\n";
  18. break;
  19. case 'chan-3':
  20. break;
  21. }
  22. }
  23. class TestRedis extends TestCase
  24. {
  25. public static function setUpBeforeClass() : void
  26. {
  27. Base::run_util();
  28. }
  29. public function testIncr()
  30. {
  31. $key = '100905';
  32. $ins = Cache::getInstance('cacheredis');
  33. $ret = $ins->incr($key);
  34. $ret = $ins->incrby($key, 6);
  35. $ret = $ins->decr($key);
  36. $ret = $ins->decrby($key, 10);
  37. $ret = $ins->get_org($key);
  38. $ret = $ins->get_org('yyyyyyxxxx');
  39. }
  40. public function testzIncr()
  41. {
  42. for ($i = 0; $i < 300; ++$i) {
  43. $x = util::mem_no();
  44. printf("%d \r\n",$x);
  45. }
  46. }
  47. public function testMember()
  48. {
  49. $mod = Model('member');
  50. $mobile = $mod->getMemberInfoByID(36490,'member_no');
  51. }
  52. public function testGetgid()
  53. {
  54. $url = 'http://images.shobserver.com/news/news/2016/12/24/0370ef86-7cea-4094-bfd4-2d6a284f8bf8.jpg?goods_id=3000';
  55. $exp = '/goods_id=(\d{1,9})$/';
  56. $x = preg_match_all($exp, $url, $match);
  57. }
  58. public function testRelation()
  59. {
  60. $x = 'a:335:{i:0;N;i:1;i:36490;i:2;i:36662;i:3;i:37260;i:4;i:37378;i:5;i:38606;i:6;i:38610;i:7;i:39254;i:8;i:39258;i:9;i:39259;i:10;i:39260;i:11;i:39265;i:12;i:39266;i:13;i:39282;i:14;i:39283;i:15;i:39285;i:16;i:39296;i:17;i:39324;i:18;i:39326;i:19;i:39348;i:20;i:39441;i:21;i:39446;i:22;i:39458;i:23;i:39478;i:24;i:39486;i:25;i:39487;i:26;i:39488;i:27;i:39489;i:28;i:39492;i:29;i:39496;i:30;i:39505;i:31;i:39520;i:32;i:39523;i:33;i:39524;i:34;i:39525;i:35;i:39526;i:36;i:39527;i:37;i:39528;i:38;i:39529;i:39;i:39531;i:40;i:39535;i:41;i:39536;i:42;i:39537;i:43;i:39538;i:44;i:39541;i:45;i:39546;i:46;i:39579;i:47;i:39585;i:48;i:39586;i:49;i:39587;i:50;i:39588;i:51;i:39604;i:52;i:39605;i:53;i:39614;i:54;i:39615;i:55;i:39616;i:56;i:39637;i:57;i:39641;i:58;i:39647;i:59;i:39648;i:60;i:39649;i:61;i:39654;i:62;i:39655;i:63;i:39656;i:64;i:39657;i:65;i:39658;i:66;i:39659;i:67;i:39660;i:68;i:39661;i:69;i:39662;i:70;i:39663;i:71;i:39664;i:72;i:39665;i:73;i:39668;i:74;i:39670;i:75;i:39673;i:76;i:39675;i:77;i:39680;i:78;i:39681;i:79;i:39682;i:80;i:39683;i:81;i:39684;i:82;i:39685;i:83;i:39686;i:84;i:39687;i:85;i:39688;i:86;i:39689;i:87;i:39690;i:88;i:39691;i:89;i:39692;i:90;i:39693;i:91;i:39694;i:92;i:39695;i:93;i:39696;i:94;i:39697;i:95;i:39698;i:96;i:39699;i:97;i:39700;i:98;i:39701;i:99;i:39702;i:100;i:39703;i:101;i:39704;i:102;i:39705;i:103;i:39706;i:104;i:39707;i:105;i:39708;i:106;i:39709;i:107;i:39710;i:108;i:39714;i:109;i:39715;i:110;i:39716;i:111;i:39717;i:112;i:39718;i:113;i:39719;i:114;i:39720;i:115;i:39733;i:116;i:39734;i:117;i:39784;i:118;i:39786;i:119;i:39797;i:120;i:39799;i:121;i:39803;i:122;i:39805;i:123;i:39807;i:124;i:39809;i:125;i:39813;i:126;i:39814;i:127;i:39834;i:128;i:39838;i:129;i:39839;i:130;i:39840;i:131;i:39842;i:132;i:39845;i:133;i:39846;i:134;i:39847;i:135;i:39848;i:136;i:39849;i:137;i:39850;i:138;i:39851;i:139;i:39852;i:140;i:39853;i:141;i:39854;i:142;i:39855;i:143;i:39856;i:144;i:39858;i:145;i:39859;i:146;i:39864;i:147;i:39865;i:148;i:39867;i:149;i:39868;i:150;i:39869;i:151;i:39870;i:152;i:39871;i:153;i:39872;i:154;i:39874;i:155;i:39875;i:156;i:39877;i:157;i:39880;i:158;i:39881;i:159;i:39884;i:160;i:39885;i:161;i:39886;i:162;i:39889;i:163;i:39897;i:164;i:39898;i:165;i:39912;i:166;i:39913;i:167;i:39914;i:168;i:39915;i:169;i:39916;i:170;i:39917;i:171;i:39922;i:172;i:39923;i:173;i:39924;i:174;i:39925;i:175;i:39938;i:176;i:39942;i:177;i:39946;i:178;i:39951;i:179;i:39953;i:180;i:39964;i:181;i:39972;i:182;i:39976;i:183;i:39978;i:184;i:39979;i:185;i:39980;i:186;i:39981;i:187;i:39983;i:188;i:39984;i:189;i:39986;i:190;i:39992;i:191;i:39993;i:192;i:39994;i:193;i:39995;i:194;i:39996;i:195;i:39998;i:196;i:39999;i:197;i:40001;i:198;i:40002;i:199;i:40004;i:200;i:40005;i:201;i:40006;i:202;i:40007;i:203;i:40008;i:204;i:40009;i:205;i:40010;i:206;i:40011;i:207;i:40012;i:208;i:40015;i:209;i:40016;i:210;i:40017;i:211;i:40019;i:212;i:40020;i:213;i:40021;i:214;i:40022;i:215;i:40023;i:216;i:40024;i:217;i:40025;i:218;i:40026;i:219;i:40027;i:220;i:40028;i:221;i:40029;i:222;i:40030;i:223;i:40031;i:224;i:40032;i:225;i:40033;i:226;i:40034;i:227;i:40035;i:228;i:40036;i:229;i:40037;i:230;i:40038;i:231;i:40039;i:232;i:40040;i:233;i:40041;i:234;i:40042;i:235;i:40043;i:236;i:40045;i:237;i:40047;i:238;i:40048;i:239;i:40049;i:240;i:40051;i:241;i:40052;i:242;i:40054;i:243;i:40055;i:244;i:40056;i:245;i:40057;i:246;i:40059;i:247;i:40060;i:248;i:40061;i:249;i:40065;i:250;i:40066;i:251;i:40071;i:252;i:40072;i:253;i:40073;i:254;i:40074;i:255;i:40075;i:256;i:40076;i:257;i:40077;i:258;i:40078;i:259;i:40079;i:260;i:40080;i:261;i:40081;i:262;i:40082;i:263;i:40083;i:264;i:40088;i:265;i:40090;i:266;i:40091;i:267;i:40094;i:268;i:40097;i:269;i:40098;i:270;i:40101;i:271;i:40102;i:272;i:40107;i:273;i:40109;i:274;i:40111;i:275;i:40114;i:276;i:40115;i:277;i:40116;i:278;i:40117;i:279;i:40118;i:280;i:40120;i:281;i:40122;i:282;i:40124;i:283;i:40125;i:284;i:40126;i:285;i:40127;i:286;i:40128;i:287;i:40130;i:288;i:40132;i:289;i:40135;i:290;i:40136;i:291;i:40140;i:292;i:40142;i:293;i:40144;i:294;i:40145;i:295;i:40150;i:296;i:40154;i:297;i:40155;i:298;i:40161;i:299;i:40164;i:300;i:40165;i:301;i:40166;i:302;i:40179;i:303;i:40180;i:304;i:40181;i:305;i:40182;i:306;i:40184;i:307;i:40185;i:308;i:40186;i:309;i:40187;i:310;i:40189;i:311;i:40190;i:312;i:40192;i:313;i:40193;i:314;i:40196;i:315;i:40213;i:316;i:40219;i:317;i:40223;i:318;i:40231;i:319;i:40233;i:320;i:40237;i:321;i:40238;i:322;i:40246;i:323;i:40247;i:324;i:40248;i:325;i:40249;i:326;i:40250;i:327;i:40251;i:328;i:40255;i:329;i:40256;i:330;i:40257;i:331;i:40258;i:332;i:40259;i:333;i:40261;i:334;i:40264;}';
  61. $y = unserialize($x);
  62. }
  63. public function testJson()
  64. {
  65. $x = '[{"comment":"njhhjks","dispalyImages":[{"imagePath":"/storage/emulated/0/Yoho/YohoBuy/Img/Entry/11.11_n@3x.png","imageState":1,"imageUrl":"/Users/stanley-king/work/PHPProject/shopnc/data/upload/upfile/20170104043357-7ab582c6-67ec-e941-4234-8fdb01d37921.png","primaryKey":"F88154BE695749FC9FAC4B984B113F40"}],"goods_id":1285,"goods_image":"http://192.168.1.200/data/upload/shop/store/goods/6/6_05065322566829042_240.jpg","images":["/Users/stanley-king/work/PHPProject/shopnc/data/upload/upfile/20170104043357-7ab582c6-67ec-e941-4234-8fdb01d37921.png"],"score":5}]';
  66. $y = json_decode($x,true);
  67. }
  68. public function testHome()
  69. {
  70. $y = 'a:1:{s:4:"item";a:5:{s:24:"s0_05360612357121233.jpg";a:4:{s:5:"image";s:24:"s0_05398626403134398.jpg";s:4:"type";s:3:"url";s:4:"data";s:156:"http://activity.m.yiguo.com/activity/201702060.html?cityid=312d0556-0671-4f2e-8bac-7b8873b5a03a&amp;preview=1&amp;utm_source=20170206&amp;utm_medium=lrlzqrj";s:5:"title";s:24:"遇见你的不二情书";}s:24:"s0_05363274022351304.jpg";a:4:{s:5:"image";s:24:"s0_05399573176047649.jpg";s:4:"type";s:7:"special";s:4:"data";s:3:"235";s:5:"title";s:24:"皮肤身材管理专场";}s:24:"s0_05373018466048170.jpg";a:4:{s:5:"image";s:24:"s0_05394487095218686.jpg";s:4:"type";s:7:"special";s:4:"data";s:3:"231";s:5:"title";s:27:"开工不能顶着熊猫眼";}s:24:"s0_05398626270780316.jpg";a:4:{s:5:"image";s:24:"s0_05398626270780316.jpg";s:4:"type";s:7:"special";s:4:"data";s:3:"230";s:5:"title";s:23:"2017 “红”运当头";}s:24:"s0_05399573071346216.jpg";a:4:{s:5:"image";s:24:"s0_05399573071346216.jpg";s:4:"type";s:7:"special";s:4:"data";s:3:"232";s:5:"title";s:21:"直男最爱桃花色";}}}';
  71. $v = unserialize($y);
  72. }
  73. public function testPublishTags()
  74. {
  75. $redis = new Redis();
  76. $redis->pconnect('127.0.0.1',6379);
  77. $redis->publish('ch_index',serialize(array('type'=>'tags','value' => 0))); // send message to channel 1.
  78. $redis->publish('ch_index',serialize(array('type'=>'special','value' => 0))); // send message to channel 1.
  79. $redis->close();
  80. }
  81. public function testPublishSpecial()
  82. {
  83. $redis = new Redis();
  84. $redis->pconnect('127.0.0.1',6379);
  85. $redis->publish('ch_index',serialize(array('type'=>'special','value' => 0))); // send message to channel 1.
  86. $redis->close();
  87. }
  88. public function testPublishSearch()
  89. {
  90. $redis = new Redis();
  91. $redis->pconnect('127.0.0.1',6379);
  92. $redis->publish('searcher',serialize(array('type'=>'init','value' => 0)));
  93. $redis->close();
  94. }
  95. public function testSubscribe()
  96. {
  97. $redis = new Redis();
  98. $redis->pconnect('127.0.0.1',6379);
  99. $data = $redis->pubsub('numsub');
  100. $data = $redis->pubsub('numsub',array('chan-1'));
  101. $redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'sub_callback');
  102. $data = $redis->pubsub('numsub');
  103. $data = $redis->pubsub('numpat');
  104. }
  105. public function testFcode()
  106. {
  107. QueueClient::push('createGoodsFCode', array('goods_commonid' => 810, 'fc_count' => 100, 'fc_prefix' => 'NWY','fc_validate' => 10));
  108. }
  109. public function testUrl()
  110. {
  111. $x= htmlspecialchars('http://t.cn/RaVl0wQ');
  112. }
  113. public function testLogic()
  114. {
  115. $y = 5;
  116. $x = !isset($y) || is_object($y) == false;
  117. $z = !isset($y) || (is_object($y) == false);
  118. }
  119. public function testWRcache()
  120. {
  121. $t = current(['1000119000003695610' => time()]);
  122. wcache("card_expired",['1000119000003695610' => time()],'');
  123. $x = rcache('card_expired','','1000119000003695610');
  124. }
  125. public function testSpeed()
  126. {
  127. for ($i = 0; $i < 1000000; ++$i) {
  128. refill\util::incr_commit('lingzh',1,100,1,true);
  129. $ret = refill\util::hget_commit_sec('lingzh',1,100,1,time(),true);
  130. }
  131. }
  132. public function testOrderSn()
  133. {
  134. $order_sn = $this->_makeOrderSn();
  135. }
  136. private function _makeOrderSn()
  137. {
  138. static $prime_num = [11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97];
  139. static $factor = 0;
  140. if($factor == 0) {
  141. $pos = mt_rand(0,count($prime_num) - 1);
  142. $factor = $prime_num[$pos];
  143. if($factor < 100) {
  144. $factor += mt_rand(100,count($prime_num) - 1);
  145. }
  146. }
  147. $prefix = (getmypid() * $factor) % 1000;
  148. return sprintf('%03d', $prefix)
  149. . sprintf('%03d', mt_rand(100,999))
  150. . sprintf('%010d', time() - 946656000)
  151. . sprintf('%06d', (float)microtime() * 1000000);
  152. }
  153. public function testSHA1()
  154. {
  155. $params['supnumber'] = 'null';
  156. $y = strtolower($params['supnumber']) == 'null' ? '' : $params['supnumber'];
  157. $z = strtolower($params['supnumber']) ?? '';
  158. $params = [];
  159. $y = strtolower($params['supnumber']) == 'null' ? '' : $params['supnumber'];
  160. $z = strtolower($params['supnumber']) ?? '';
  161. }
  162. public function testJsonEmpty()
  163. {
  164. $resp = json_decode('',true);
  165. }
  166. public function testFormat()
  167. {
  168. $body = 'a2421040915130540';
  169. $ret = preg_match('/^\d{4}(?P<month>\d{2})(?P<day>\d{2})(?P<hour>\d{2})(?P<min>\d{2})\d{4}/u', $body, $matches);
  170. $short_no = substr('1000115100002086143',-6);
  171. }
  172. public static function tearDownAfterClass() : void
  173. {
  174. }
  175. }