浏览代码

1. cmemutil去掉cas接口, 2. bigresponse去掉对req()的输出.

gwang 5 年之前
父节点
当前提交
25645514b4
共有 3 个文件被更改,包括 41 次插入42 次删除
  1. 4 3
      Gameserver/Amfphp/index.php
  2. 5 6
      Gameserver/Amfphp/util/CMemBase.php
  3. 32 33
      Gameserver/Amfphp/util/CRedisUtil.php

+ 4 - 3
Gameserver/Amfphp/index.php

@@ -92,6 +92,7 @@ class Index {
 
     static function OverPass($resp) {
         $ret = JsonUtil::encode($resp);                                         # 返回值, 数据层协议:JSON
+
         $errinfo = ob_get_clean();                                              # 检查并截获异常输出
         if (self::$isDebugging) {                                               # 附加调试信息和异常输出
             $ret .= '<br/><hr/><font color=\'#6666FF\'>' . self::$debugMsg;     # 附加调试信息,
@@ -105,11 +106,11 @@ class Index {
 # 返回数据, 传输层编码(一律deflate压缩)
         $ret = gzdeflate($ret);                                                 # 不管请求时使用的是什么方法, 返回时一律使用deflate压缩
         $retLen = strlen($ret);                                                 # 计算下返回值长度.
+
         if ($retLen > (1024 * self::$bigRespInKbs)) {                           # 长度大于50k时记录超大返回值日志.
-            CLog::warn("Big Response:\n"                                        # 带有\n转义符的时候, 必须用双引号
-                    . "\t" . JsonUtil::encode(req()) . "\n"                      # 请求串
+            CLog::warn("Big Response:\n"                                        # 带有\n转义符的时候, 必须用双引号 
                     . "\t" . substr(JsonUtil::encode($resp), 0, 30)             # 返回串(截断为30bytes)
-                    . "..., over " . CommUtil::floatToInt($retLen / 1024) . "kbs.", "Index"); # 返回串长度
+                    . "..., about " . CommUtil::floatToInt($retLen / 1024) . "kbs.", "Index"); # 返回串长度
         }
         header('Cache-Control: no-store');                                      # 防御缓存设施
         header('Host:' . PHP_OS . "-" . $_SERVER['SERVER_ADDR']);               # 这里提取服务器地址返给客户端,方便留意负载均衡/弹性扩容的效果

+ 5 - 6
Gameserver/Amfphp/util/CMemBase.php

@@ -13,8 +13,7 @@ namespace loyalsoft;
  * CMemNoSqL db 操作基类
  * @author gwang (mail@wanggangzero.cn)
  */
-abstract class CMemBase
-{
+abstract class CMemBase {
 
     /**
      * 连接
@@ -77,10 +76,10 @@ abstract class CMemBase
      */
     abstract public function setMutlti($dict, $expireTs = 0);
 
-    /**
-     * Compare and set 比较并且(结果相同则)写入
-     */
-    abstract public function cas($key, $value, $ts);
+//    /**
+//     * Compare and set 比较并且(结果相同则)写入
+//     */
+//    abstract public function cas($key, $value, $ts);
 
     /**
      * 复制

+ 32 - 33
Gameserver/Amfphp/util/CRedisUtil.php

@@ -26,8 +26,7 @@ require __DIR__ . '/Predis/Autoloader.php';
  *          1.0.0  pguan,基础功能, 方法与memcache看齐. <br/>
  */
 class CRedisUtil extends CMemBase {
-
-    public $keyDic = null;
+//    public $keyDic = null;
 
     /**
      *
@@ -171,7 +170,7 @@ class CRedisUtil extends CMemBase {
             'port' => $port,
             'password' => $pwd,
         ));
-        $this->keyDic = new \stdClass();
+//        $this->keyDic = new \stdClass();
         return $this;
     }
 
@@ -193,7 +192,7 @@ class CRedisUtil extends CMemBase {
         if (!$result || $result == "" || $result == null) {
             return null;
         }
-        $this->keyDic->$key = $result;
+//        $this->keyDic->$key = $result;
         return JsonUtil::decode($result);
     }
 
@@ -226,35 +225,35 @@ class CRedisUtil extends CMemBase {
         return true;
     }
 
-    /**
-     * 安全的写入操作
-     * @deprecated since version 1.0 云平台暂时不支持
-     * @param string $key
-     * @param any $value
-     * @return boolean 成功true,失败false
-     */
-    public function cas($key, $value, $ts = 0) {
-        if (false) {                               # ps. 各云平台皆不支持eval方法执行lua脚本.等开放支持的时候才是真正支持cas的时候
-            $castoken = $this->keyDic->$key;
-#                                                  # 定义一段脚本
-            $script = <<<casscript
-if redis.call("get",KEYS[1]) == "$castoken"
-then
-    return redis.call("set",KEYS[1],ARGV[1])
-else
-    return 0
-end
-casscript;
-            $ret = $this->redis->eval($script, 1, $key, $value); # redis 执行lua脚本
-            if (0 == $ret) {
-                return false;
-            }
-            return true;
-        }
-
-        // 非线程安全,原因见下
-        return $this->set($key, $value, $ts);
-    }
+//    /**
+//     * 安全的写入操作
+//     * @deprecated since version 1.0 云平台暂时不支持
+//     * @param string $key
+//     * @param any $value
+//     * @return boolean 成功true,失败false
+//     */
+//    public function cas($key, $value, $ts = 0) {
+//        if (false) {                               # ps. 各云平台皆不支持eval方法执行lua脚本.等开放支持的时候才是真正支持cas的时候
+//            $castoken = $this->keyDic->$key;
+//#                                                  # 定义一段脚本
+//            $script = <<<casscript
+//if redis.call("get",KEYS[1]) == "$castoken"
+//then
+//    return redis.call("set",KEYS[1],ARGV[1])
+//else
+//    return 0
+//end
+//casscript;
+//            $ret = $this->redis->eval($script, 1, $key, $value); # redis 执行lua脚本
+//            if (0 == $ret) {
+//                return false;
+//            }
+//            return true;
+//        }
+//
+//        // 非线程安全,原因见下
+//        return $this->set($key, $value, $ts);
+//    }
 
     /**
      * 删除一个或多个指定键值