Quellcode durchsuchen

add tw sub-directory

joe vor 4 Jahren
Ursprung
Commit
cced6e0b5f

+ 12 - 0
tw/README.md

@@ -0,0 +1,12 @@
+# *tw*
+
+包含了
+
+## 和系统优化相关的代码
+
+主要包含了 redis 部分替换 mysql 用于提高读性能
+beanstalk 异步操作
+
+## twong 自定义逻辑
+
+

+ 14 - 0
tw/redis/Base.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace tw\redis;
+
+
+abstract class Base
+{
+    /**
+     * 需函数,返回键
+     * @param integer|string $word: 组成键的关键部分
+     * @return string
+     */ 
+    abstract protected function key($word=false) : string;
+}

+ 41 - 0
tw/redis/HashTrait.php

@@ -0,0 +1,41 @@
+<?php
+namespace tw\redis;
+
+use crmeb\utils\Redis;
+
+trait HashTrait 
+{
+    public function get($word, $attr) : string
+    {
+        return Redis::hGet($this->key($word), $attr);
+    }
+
+    public function gets($word, $attrs) : array
+    {
+        return Redis::hMGet($this->key($word), $attrs);
+    }
+
+    public function set($word, $attr, $value) : bool
+    {
+        return Redis::hSet($this->key($word), $attr, $value);
+    }
+
+    public function sets($word, $attrs) : bool
+    {
+        return Redis::hMSet($this->key($word), $attrs);
+    }
+
+    public function dels($word, $attrs) : int
+    {
+        if (is_string($attrs)) {
+            return Redis::hDel($this->key($word), $attrs);
+        }else if (is_array($attrs)) {
+            return Redis::hDel($this->key($word), ...$attrs);
+        }
+    }
+
+    public function getAll($word) : array
+    {
+        return Redis::hGetAll($this->key($word));
+    }
+}

+ 14 - 0
tw/redis/ProductCategoryRds.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace tw\redis;
+
+
+class ProductCategoryRds extends Base
+{
+    use HashTrait;
+
+    protected function key($cate_id=false) : string
+    {
+        return 'store:category:' . $cate_id;
+    }
+}

+ 13 - 0
tw/redis/ProductRds.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace tw\redis;
+
+class ProductRds extends Base 
+{
+    use HashTrait;
+
+    protected function key($pid=false) : string
+    {
+        return 'store:product:' . $pid;
+    }
+}

+ 15 - 0
tw/redis/UserRds.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace tw\redis;
+
+use crmeb\utils\Redis;
+
+class UserRds extends Base
+{
+    use HashTrait;
+
+    protected function key($uid=false) : string
+    {
+        return 'user:' . $uid;
+    }
+}

+ 1 - 0
vendor/composer/autoload_psr4.php

@@ -8,6 +8,7 @@ $baseDir = dirname($vendorDir);
 return array(
     'xin\\helper\\' => array($vendorDir . '/xin/helper/src'),
     'xin\\container\\' => array($vendorDir . '/xin/container/src'),
+    'tw\\' => array($baseDir . '/tw'),
     'think\\view\\driver\\' => array($vendorDir . '/topthink/think-view/src'),
     'think\\captcha\\' => array($vendorDir . '/topthink/think-captcha/src'),
     'think\\app\\' => array($vendorDir . '/topthink/think-multi-app/src'),

+ 5 - 0
vendor/composer/autoload_static.php

@@ -37,6 +37,7 @@ class ComposerStaticInitf16474ac994ccc25392f403933800b79
         ),
         't' => 
         array (
+            'tw\\' => 3,
             'think\\view\\driver\\' => 18,
             'think\\captcha\\' => 14,
             'think\\app\\' => 10,
@@ -151,6 +152,10 @@ class ComposerStaticInitf16474ac994ccc25392f403933800b79
         array (
             0 => __DIR__ . '/..' . '/xin/container/src',
         ),
+        'tw\\' => 
+        array (
+            0 => __DIR__ . '/../..' . '/tw',
+        ),
         'think\\view\\driver\\' => 
         array (
             0 => __DIR__ . '/..' . '/topthink/think-view/src',

+ 1 - 1
vendor/services.php

@@ -1,5 +1,5 @@
 <?php 
-// This file is automatically generated at:2021-07-03 23:57:18
+// This file is automatically generated at:2021-09-25 11:48:14
 declare (strict_types = 1);
 return array (
   0 => 'think\\captcha\\CaptchaService',