瀏覽代碼

add redis and update http protocol parser

walkor 10 年之前
父節點
當前提交
09ee69c6fd
共有 3 個文件被更改,包括 36 次插入1 次删除
  1. 20 0
      GatewayWorker/Lib/Store.php
  2. 15 0
      GatewayWorker/Lib/StoreDriver/Redis.php
  3. 1 1
      Workerman/Protocols/Http.php

+ 20 - 0
GatewayWorker/Lib/Store.php

@@ -52,6 +52,26 @@ class Store
             }
             return self::$instance[$config_name];
         }
+        // redis 驱动
+        elseif(\Config\Store::$driver == \Config\Store::DRIVER_REDIS)
+        {
+            if(!isset(\Config\Store::$$config_name))
+            {
+                echo "\\Config\\Store::$config_name not set\n";
+                throw new \Exception("\\Config\\Store::$config_name not set\n");
+            }
+            if(!isset(self::$instance[$config_name]))
+            {
+                self::$instance[$config_name] = new \GatewayWorker\Lib\StoreDriver\Redis();
+                // 只选择第一个ip作为服务端
+                $address = current(\Config\Store::$$config_name);
+                list($ip, $port) = explode(':', $address);
+                $timeout = 1;
+                self::$instance[$config_name]->connect($ip, $port, $timeout);
+                self::$instance[$config_name]->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_IGBINARY);
+            }
+            return self::$instance[$config_name];
+        }
         // 文件驱动
         else 
         {

+ 15 - 0
GatewayWorker/Lib/StoreDriver/Redis.php

@@ -0,0 +1,15 @@
+<?php
+namespace GatewayWorker\Lib\StoreDriver;
+
+/**
+ * 
+ * Redis
+ */
+
+class Redis extends \Redis
+{
+    public function increment($key)
+    {
+        return parent::incr($key);
+    }
+}

+ 1 - 1
Workerman/Protocols/Http.php

@@ -193,7 +193,7 @@ class Http
         $_SERVER['REMOTE_ADDR'] = $connection->getRemoteIp();
         $_SERVER['REMOTE_PORT'] = $connection->getRemotePort();
         
-        return $recv_buffer;
+        return array('get'=>$_GET, 'post'=>$_POST, 'cookie'=>$_COOKIE, 'server'=>$_SERVER, 'files'=>$_FILES);
     }
     
     /**