public static void ReadCallback(IAsyncResult ar) { StateObject state = (StateObject)ar.AsyncState; RedisSocket redis_socket = state.redis_socket; Socket sock = state.socket; int bytesRead = sock.EndReceive(ar); if (bytesRead > 0) { redis_socket.on_data(state.buffer, bytesRead); sock.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state); } }
/* * public static string redis_cmd(string[] cmd_set) * { * System.Text.UTF8Encoding c=new System.Text.UTF8Encoding(); * * string data = string.Format ("*{0}\r\n", cmd_set.Length); * for(int i=0;i<cmd_set.Length;i++) * { * byte[] d = c.GetBytes (cmd_set [i]);// System.Convert.FromBase64String(cmd_set[i]); * data += string.Format ("${0}\r\n{1}\r\n", d.Length, cmd_set [i]); * } * data += "\r\n"; * return data; * }*/ //测试 public static void test() { JsonReader jr = new JsonReader(tools.file_get_contents("config.json")); Dictionary <string, object> config = (Dictionary <string, object>)jr.Deserialize(); ChanelMp mp1 = Instance(); mp1.set_method("C2S_玩家登陆"); mp1.set_param("gid", "1_3"); tools.file_put_contents("hello.txt", tools.to_json(mp1, true)); RedisSocket c1 = new RedisSocket(); RedisSocket c2 = new RedisSocket(); c1.cfg((string)config["c1_host"], (int)config["c1_port"]); c2.cfg((string)config["c2_host"], (int)config["c2_port"]); string cmdline = "hello word 消息信息!"; c2.on_data(cmdline); c2.On_cmd_set_callback = new On_cmd_set_callback(mp1.On_cmd_set_callback2); c1.On_cmd_set_callback = new On_cmd_set_callback(mp1.On_cmd_set_callback1); c1.send(new string[] { "set", "a", "a===1" }); c1.send(new string[] { "set", "b", "b===2" }); c1.send(new string[] { "set", "c", "c===3" }); c1.send(new string[] { "keys", "*" }); c1.send(new string[] { "get", "c" }); //c1.send(new string[] { "subscribe", "h", "g", "b" }); c1.send("psubscribe h g b"); //file_put_contents ("hello.txt", redis_cmd (cmd_set)); Debug.Log("--------"); // c2.game_call (mp1); }