stanley-king 4 lat temu
rodzic
commit
10aad83142

+ 44 - 13
core/framework/cache/cache.redis.php

@@ -11,7 +11,8 @@ class CacheRedis extends Cache
 	private $connected;
 	private $type;
 	private $prefix;
-    public function __construct() {
+    public function __construct()
+    {
     	$this->config = C('redis');
     	if (empty($this->config['slave'])) $this->config['slave'] = $this->config['master'];
     	$this->prefix = $this->config['prefix'] ? $this->config['prefix'] : substr(md5($_SERVER['HTTP_HOST']), 0, 6).'_';
@@ -30,7 +31,6 @@ class CacheRedis extends Cache
 	        $this->handler  = new Redis;
 	        $this->enable = $this->handler->$func($this->config['master']['host'], $this->config['master']['port']);
 	        $_cache = $this->handler;
-//            $_cache->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
     	}
     }
 
@@ -43,7 +43,6 @@ class CacheRedis extends Cache
 	        $this->handler = new Redis;
 	        $this->enable = $this->handler->$func($this->config['slave']['host'], $this->config['slave']['port']);
 	        $_cache = $this->handler;
-//            $_cache->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
     	}
     }
 
@@ -67,7 +66,6 @@ class CacheRedis extends Cache
     	$this->type = $prefix;
 
         $value = serialize($value);
-
         if(is_int($expire)) {
             $result = $this->handler->setex($this->_key($key), $expire, $value);
         }else{
@@ -76,6 +74,40 @@ class CacheRedis extends Cache
         return $result;
     }
 
+    public function set_org($key,$val,$prefix = '')
+    {
+        $this->init_master();
+        if (!$this->enable) return false;
+        $this->type = $prefix;
+        $result = $this->handler->set($this->_key($key), $val);
+
+        return $result;
+    }
+
+    public function incr($key,$prefix = '')
+    {
+        $this->init_master();
+        if (!$this->enable) return false;
+        $this->type = $prefix;
+        $key = $this->_key($key);
+        $value = $this->handler->incr($key);
+        return $value;
+    }
+
+    public function incrby($key,$val,$prefix = '') {
+
+    }
+
+    public function decr($key,$prefix)
+    {
+
+    }
+
+    public function decrby($key,$val,$prefix = '')
+    {
+
+    }
+
     public function zIncrBy($key, $value, $member,$prefix='')
     {
         $this->init_master();
@@ -96,7 +128,8 @@ class CacheRedis extends Cache
         return $result;
     }
 
-    public function hset($name, $prefix, $data) {
+    public function hset($name, $prefix, $data)
+    {
         $this->init_master();
         if (!$this->enable || !is_array($data) || empty($data)) return false;
         $this->type = $prefix;
@@ -141,15 +174,13 @@ class CacheRedis extends Cache
             } else {
                 return $this->handler->del($this->_key($name));
             }
-        } else {
-            if (is_array($name)) {
-                foreach ($name as $key => $value) {
-                    $this->handler->hdel($this->_key($name), $key);
-                }
-                return true;
-            } else {
-                return $this->handler->hdel($this->_key($name), $key);
+        } elseif (is_array($name)) {
+            foreach ($name as $key => $value) {
+                $this->handler->hdel($this->_key($name), $key);
             }
+            return true;
+        } else {
+            return $this->handler->hdel($this->_key($name), $key);
         }
     }
 

+ 1 - 1
core/framework/function/core.php

@@ -1905,7 +1905,7 @@ function rcache($key = null, $prefix = '', $fields = '*')
  * @param int $period 缓存周期  单位分,0为永久缓存
  * @return bool 返回值
  */
-function wcache($key = null, $data = array(), $prefix, $period = 0)
+function wcache($key, $data, $prefix, $period = 0)
 {
     if ($key===null || !C('cache_open') || !is_array($data)) {
     	return false;

+ 0 - 1
helper/refill/RefillFactory.php

@@ -420,7 +420,6 @@ class RefillFactory
                         $trans->rollback();
                         Log::record("Error:" . $ex->getMessage(),Log::ERR);
                     }
-
                 }
                 else {
                     $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,不可重试.");

+ 30 - 0
helper/refill/refill.puml

@@ -0,0 +1,30 @@
+@startuml
+title refill sequence
+'注释: https://plantuml.com/zh/sequence-diagram
+
+
+actor Merchant
+boundary LoadBlancer
+collections AccNginx
+collections AccServer
+collections QueueServer
+collections DispatchServer
+boundary ChannelServer
+
+Merchant --> LoadBlancer: post
+LoadBlancer -> AccNginx: Dispatch
+AccNginx --> AccServer: Dispatch
+AccServer --> AccServer: Check
+AccServer --> QueueServer: push
+
+DispatchServer --> QueueServer: pop
+DispatchServer --> DispatchServer: AddOrder
+DispatchServer --> ChannelServer: push
+
+ChannelServer --> LoadBlancer: callback
+
+LoadBlancer --> AccNginx: Dispatch
+
+AccNginx --> AccServer: notify
+
+@enduml

+ 2 - 2
test/TestAccountHelper.php

@@ -8,8 +8,8 @@ use PHPUnit\Framework\TestCase;
  * Date: 16/6/27
  * Time: 下午10:27
  */
-
-define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
+define('APP_ID', 'test');
+define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
 
 require_once(BASE_ROOT_PATH . '/global.php');
 require_once(BASE_CORE_PATH . '/lrlz.php');

+ 22 - 13
test/TestRedis.php

@@ -1,15 +1,12 @@
-<?php
+<?php declare(strict_types=1);
 
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2016/12/24
- * Time: 下午3:58
- */
+use PHPUnit\Framework\TestCase;
+define('APP_ID', 'test');
+define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_CORE_PATH . '/lrlz.php');
+require_once(BASE_ROOT_PATH . '/fooder.php');
 
-define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
-
-require_once (BASE_ROOT_PATH . '/fooder.php');
 require_once (BASE_ROOT_PATH . '/helper/util_helper.php');
 
 
@@ -27,15 +24,27 @@ function sub_callback($redis, $chan, $msg)
     }
 }
 
-class TestRedis extends PHPUnit_Framework_TestCase
+class TestRedis extends TestCase
 {
-    public static function setUpBeforeClass()
+    public static function setUpBeforeClass() : void
     {
         Base::run_util();
     }
 
     public function testIncr()
     {
+        $key = '10090';
+        $ins = Cache::getInstance('cacheredis');
+        $ins->set_org($key,0);
+        $ins->incr($key);
+
+
+
+
+    }
+
+    public function testzIncr()
+    {
         for ($i = 0; $i < 300; ++$i) {
             $x = util::mem_no();
             printf("%d \r\n",$x);
@@ -126,7 +135,7 @@ class TestRedis extends PHPUnit_Framework_TestCase
     }
 
 
-    public static function tearDownAfterClass()
+    public static function tearDownAfterClass() : void
     {
     }
 }

+ 73 - 0
test/TestTask.php

@@ -0,0 +1,73 @@
+<?php declare(strict_types=1);
+
+use PHPUnit\Framework\TestCase;
+
+define('APP_ID', 'test');
+define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
+
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_CORE_PATH . '/lrlz.php');
+require_once(BASE_ROOT_PATH . '/fooder.php');
+
+class TestTask extends TestCase
+{
+    public static function setUpBeforeClass() : void
+    {
+        Base::run_util();
+    }
+
+    public function testXRange()
+    {
+        $xrange = function ($start, $end, $step = 1) {
+            for ($i = $start; $i <= $end; $i += $step) {
+                yield $i;
+            }
+        };
+
+        $ins = $xrange(1,100);
+        var_dump($xrange);
+        $type = $ins instanceof Iterator;
+
+
+        foreach ($xrange(1, 1000000) as $num) {
+            Log::record("num={$num}",Log::DEBUG);
+        }
+    }
+
+    public function testLogger()
+    {
+        $log = function ($fileName) {
+            $fileHandle = fopen($fileName, 'a');
+            while (true) {
+                fwrite($fileHandle, yield . "\n");
+            }
+        };
+
+        $logger = $log(__DIR__ . '/log');
+        $logger->send('Foo');
+        $logger->send('Bar');
+    }
+
+    public function testGener()
+    {
+        $generator = function() {
+            $ret = yield 'yield1';
+            Log::record($ret,Log::DEBUG);
+            $ret = yield 'yield2';
+            Log::record($ret,Log::DEBUG);
+        };
+
+        $gen = $generator();
+        Log::record($gen->current(),Log::DEBUG);
+        $ret = $gen->send('ret1');
+        Log::record($ret,Log::DEBUG);
+        $ret = $gen->send('ret2');
+        Log::record($ret,Log::DEBUG);
+
+        //var_dump($gen->send('ret1')); // string(4) "ret1"   (the first var_dump in gen)
+        // string(6) "yield2" (the var_dump of the ->send() return value)
+//        var_dump($gen->send('ret2')); // string(4) "ret2"   (again from within gen)
+        // NULL               (the return value of ->send())
+
+    }
+}