Procházet zdrojové kódy

更新 HasnTrait 的接口函数名以区分 StringTrait

joe před 3 roky
rodič
revize
f0aae62012

+ 7 - 7
app/admin/controller/Test.php

@@ -103,15 +103,15 @@ class Test
     protected function test_redis()
     {
         $ur = new UserRds();
-        $ur->set(1, 'streak', 3);
-        echo $ur->get(1, 'streak') . '</br>';
-        echo $ur->get(1, 'notexists') . '</br>';
+        $ur->hset(1, 'streak', 3);
+        echo $ur->hget(1, 'streak') . '</br>';
+        echo $ur->hget(1, 'notexists') . '</br>';
 
-        $ur->sets(1, ['name'=>'didi', 'age'=>28]);
-        print_r($ur->gets(1, ['name', 'age'])) . '</br>';
-        print_r($ur->gets(1, ['friends', 'teacher'])) . '</br>';
+        $ur->hmset(1, ['name'=>'didi', 'age'=>28]);
+        print_r($ur->hmget(1, ['name', 'age'])) . '</br>';
+        print_r($ur->hmget(1, ['friends', 'teacher'])) . '</br>';
 
-        print_r($ur->getAll(1)) . '</br>';
+        print_r($ur->hget_all(1)) . '</br>';
     }
 
     protected function test_enterprise_pay()

+ 4 - 4
app/api/controller/coin/UserCoinController.php

@@ -96,7 +96,7 @@ class UserCoinController
         // 獲取用戶進度
         $uid = $request->uid();
         $rds = new UserRds();
-        $mymining = json_decode($rds->get($uid, UserRds::FIELD_MINING), true);
+        $mymining = json_decode($rds->hget($uid, UserRds::FIELD_MINING), true);
         if (!$mymining) {
             $mymining = $defStatus;
             return app('json')->successful($defStatus);
@@ -104,7 +104,7 @@ class UserCoinController
         //
         if ($mymining['progress'] > 0.0) {
             $mymining = $this->calcMining($uid, $coinInfo, $mymining);
-            $rds->set($uid, UserRds::FIELD_MINING, json_encode($mymining));
+            $rds->hset($uid, UserRds::FIELD_MINING, json_encode($mymining));
         } else {    // 本次挖矿已经结束
             $mymining['total'] = UserCoin::where('uid', $uid)->where('symbol', $symbol)->value('balance') ?? 0.0;
             $mymining['symbol'] = $symbol;
@@ -227,7 +227,7 @@ class UserCoinController
         }
         // 是否已经开启
         $rds = new UserRds();
-        $mining = json_decode($rds->get($uid, UserRds::FIELD_MINING), true);
+        $mining = json_decode($rds->hget($uid, UserRds::FIELD_MINING), true);
         if ($mining) {
             if (
                 isset($mining['progress']) &&
@@ -264,7 +264,7 @@ class UserCoinController
         $hour = random_int($hours[0], $hours[1]);
         $stop = $now + $hour * 60 * 60;
 
-        $suc = $rds->set($uid, UserRds::FIELD_MINING, json_encode([
+        $suc = $rds->hset($uid, UserRds::FIELD_MINING, json_encode([
             'boot' => $now,
             'step' => $step,
             'stop' => $stop,

+ 1 - 1
app/api/controller/user/UserExtractController.php

@@ -62,7 +62,7 @@ class UserExtractController
         $data['extractBank'] = explode("\n", is_array($extractBank) ? (isset($extractBank[0]) ? $extractBank[0] : $extractBank) : $extractBank);
         $data['minPrice'] = sys_config('user_extract_min_price'); //提现最低金额
         // 输入记忆
-        $cach = (new UserRds)->gets($user['uid'], [
+        $cach = (new UserRds)->hmget($user['uid'], [
             UserRds::FILED_WXPAYNAME,
             UserRds::FIELD_BANKCARDNO,
             UserRds::FIELD_BANKUSER,

+ 1 - 7
app/api/controller/user/UserNotificationController.php

@@ -1,13 +1,7 @@
 <?php
 namespace app\api\controller\user;
 
-use app\models\coin\UserCoinTransfer;
-use app\models\system\DictCoin;
 use app\Request;
-use crmeb\services\JsonService;
-use think\facade\Config;
-use think\facade\Log;
-use think\facade\Cache;
 use tw\redis\UserRds;
 
 /**
@@ -31,7 +25,7 @@ class UserNotificationController {
     public function snapshot(Request $request) {
         $uid = $request->uid();
         // 未读消息
-        $unread = (new UserRds)->get($uid, UserRds::FIELD_UNREAD) ?? 0;
+        $unread = (new UserRds)->hget($uid, UserRds::FIELD_UNREAD) ?? 0;
 
         return app('json')->successful([
             'unread'=> intval($unread),

+ 2 - 2
app/api/controller/wechat/AuthController.php

@@ -101,7 +101,7 @@ class AuthController
             $cache_key = md5(time() . $code);
             Cache::set('eb_api_code_' . $cache_key, $json2sess, SECONDS_OF_ONEDAY);
             // 获取用户上次刷新时间,距今超过 2 周就刷新
-            $last = (new UserRds)->get($uid, UserRds::FIELD_LASTREFRESH);
+            $last = (new UserRds)->hget($uid, UserRds::FIELD_LASTREFRESH);
             if (time() - intval($last) >= SECONDS_OF_ONEDAY * 20) {
                 return app('json')->successful([
                     'token' => '',
@@ -255,7 +255,7 @@ class AuthController
             $token = UserToken::createToken($userInfo, 'routine');
         if ($token) {
             event('UserLogin', [$userInfo, $token]);
-            (new UserRds)->set($uid, UserRds::FIELD_LASTREFRESH, time());
+            (new UserRds)->hset($uid, UserRds::FIELD_LASTREFRESH, time());
             return app('json')->successful('登陆成功!', [
                 'token' => $token->token,
                 'userInfo' => $userInfo,

+ 5 - 5
tw/lib/robot/Robots.php

@@ -178,7 +178,7 @@ class Robots
         }
 
         foreach (self::$robots as $robot) {
-            (new RobotsInfoRds)->set(false, $robot['uid'], $robot);
+            (new RobotsInfoRds)->hset(false, $robot['uid'], $robot);
         }
     }
 
@@ -187,7 +187,7 @@ class Robots
      */
     public static function from_redis()
     {
-        $robots = (new RobotsInfoRds)->getAll(false);
+        $robots = (new RobotsInfoRds)->hget_all(false);
         foreach ($robots as $k => $v) {
             $robots[$k] = json_decode($v, true);
         }
@@ -215,14 +215,14 @@ class Robots
             $value = tw_divf(tw_rand(500, 5000), 100.0, 2);
 
             // get - update - set
-            $srobot = (new RobotsInfoRds)->get(false, $uid);
+            $srobot = (new RobotsInfoRds)->hget(false, $uid);
             if (!$srobot) {
                 console::log('not found: uid=' . $uid);
             }
             $robot = json_decode($srobot, true);
             $robot['value'] = tw_addf($robot['value'], $value, 2);
 
-            (new RobotsInfoRds)->set(false, $uid, $robot);
+            (new RobotsInfoRds)->hset(false, $uid, $robot);
         }
     }
 
@@ -239,7 +239,7 @@ class Robots
      */
     public static function first_n_by_value(int $n): array
     {
-        $robots = (new RobotsInfoRds)->getAll(false);
+        $robots = (new RobotsInfoRds)->hget_all(false);
         foreach ($robots as $uid => $robot) {
             $robots[$uid] = json_decode($robot, true);
         }

+ 6 - 6
tw/redis/traits/HashTrait.php

@@ -17,12 +17,12 @@ trait HashTrait
      * @param string $attr
      * @return string
      */
-    public function get($word, string $attr): string
+    public function hget($word, string $attr): string
     {
         return TwRedis::hGet($this->key($word), $attr);
     }
 
-    public function gets($word, array $attrs): array
+    public function hmget($word, array $attrs): array
     {
         return TwRedis::hMGet($this->key($word), $attrs);
     }
@@ -30,7 +30,7 @@ trait HashTrait
     /**
      * set hash attr
      */
-    public function set($word, string $attr, $value): bool
+    public function hset($word, string $attr, $value): bool
     {
         if (is_array($value)) {
             $value = json_encode($value);
@@ -44,7 +44,7 @@ trait HashTrait
      * @param array $attrs: ['attr1'=>'value1', 'attr2' => 'value2']
      * @return bool
      */
-    public function sets($word, array $attrs): bool
+    public function hmset($word, array $attrs): bool
     {
         return TwRedis::hMSet($this->key($word), $attrs);
     }
@@ -85,7 +85,7 @@ trait HashTrait
         return TwRedis::hVals($this->key($word));
     }
 
-    public function dels($word, $attrs): int
+    public function hmdel($word, $attrs): int
     {
         if (is_string($attrs)) {
             return TwRedis::hDel($this->key($word), $attrs);
@@ -94,7 +94,7 @@ trait HashTrait
         }
     }
 
-    public function getAll($word): array
+    public function hget_all($word): array
     {
         return TwRedis::hGetAll($this->key($word));
     }

+ 2 - 2
tw/services/controller/PaymentService.php

@@ -162,12 +162,12 @@ class PaymentService
             case 'weixin':
                 $openid = WechatUser::where('uid', $extractInfo['uid'])->value('routine_openid');
                 //
-                (new UserRds)->set($extractInfo['uid'], UserRds::FILED_WXPAYNAME, $extractInfo['real_name']);
+                (new UserRds)->hset($extractInfo['uid'], UserRds::FILED_WXPAYNAME, $extractInfo['real_name']);
                 //
                 return MachantPay::toWeixin($openid, $trade_no, $extractInfo['extract_price'], '佣金提现', $extractInfo['real_name']);
             case 'bank':
                 // 记忆银行信息
-                (new UserRds)->sets($extractInfo['uid'], [
+                (new UserRds)->hmset($extractInfo['uid'], [
                     UserRds::FIELD_BANKCARDNO => $extractInfo['bank_code'],
                     UserRds::FIELD_BANKUSER => $extractInfo['real_name'],
                     UserRds::FIELD_BANKNAME => $extractInfo['bank_address'],