示例#1
0
        private bool GetRedisKeyValue(RedisClient client, string key, out int error, out string msg)
        {
            error = 0;
            msg   = "";
            int count = 10;

            if (key.StartsWith("__GLOBAL_CHANGE_KEYS_NEW") || key.StartsWith("__QUEUE_REDIS_SYNC"))
            {
                byte[][]      keyBytes = client.HKeys(key);
                StringBuilder sb       = new StringBuilder();
                sb.AppendFormat("Count:{0:D}", keyBytes.Length);
                sb.AppendLine("[");
                foreach (var buffer in keyBytes)
                {
                    sb.AppendFormat("    {0}", Encoding.UTF8.GetString(buffer));
                    sb.AppendLine();
                }
                sb.AppendLine("]");
                msg = sb.ToString();
            }
            else if (key.StartsWith("__GLOBAL_CHANGE_KEYS"))
            {
                byte[][]      buffers = client.ZRange(key, 0, int.MaxValue);
                StringBuilder sb      = new StringBuilder();
                sb.AppendFormat("Count:{0:D}", buffers.Length);
                sb.AppendLine("[");
                foreach (var buffer in buffers)
                {
                    var temp = ProtoBufUtils.Deserialize <KeyValuePair <string, byte[]> >(buffer);
                    sb.AppendFormat("    {0}", temp.Key);
                    sb.AppendLine();
                }
                sb.AppendLine("]");
                msg = sb.ToString();
            }
            else if (key.StartsWith("__GLOBAL_SESSIONS"))
            {
                byte[] data = client.Get <byte[]>(key) ?? new byte[0];
                var    dict = ProtoBufUtils.Deserialize <ConcurrentDictionary <Guid, GameSession> >(data);
                msg  = "Count:" + dict.Count + "\r\n";
                msg += JsonHelper.FormatJsonToString(JsonUtils.Serialize(dict.Values.ToList()));
            }
            else if (key.StartsWith("__GLOBAL_SQL_CHANGE_KEYS_NEW") || key.StartsWith("__QUEUE_SQL_SYNC_WAIT"))
            {
                byte[][]      keyBytes = client.HKeys(key);
                StringBuilder sb       = new StringBuilder();
                sb.AppendLine("Count:" + keyBytes.Length);
                sb.AppendLine("[");
                foreach (var buffer in keyBytes)
                {
                    sb.AppendFormat("    {0}", Encoding.UTF8.GetString(buffer));
                    sb.AppendLine();
                }
                sb.AppendLine("]");
                msg = sb.ToString();
            }
            else if (key.StartsWith("__GLOBAL_SQL_CHANGE_KEYS"))
            {
                byte[] data = client.Get <byte[]>(key) ?? new byte[0];
                var    dict = ProtoBufUtils.Deserialize <Dictionary <string, bool> >(data) ??
                              new Dictionary <string, bool>();
                msg  = "Count:" + dict.Count + "\r\n";
                msg += JsonHelper.FormatJsonToString(JsonUtils.Serialize(dict.Keys.ToList()));
            }
            else if (key.StartsWith("EntityPrimaryKey_"))
            {
                var val = client.Get <long>(key);
                msg = string.Format("{0}:\t{1}", key, val);
            }
            else if (key.StartsWith("__GLOBAL_SQL_STATEMENT") || key.StartsWith("__QUEUE_SQL_SYNC"))
            {
                //sql
                StringBuilder sb      = new StringBuilder();
                byte[][]      buffers = client.ZRange(key, 0, int.MaxValue);
                int           index   = 0;
                foreach (var buffer in buffers)
                {
                    if (index >= count)
                    {
                        break;
                    }
                    var temp = ProtoBufUtils.Deserialize(buffer, typeof(SqlStatement));
                    sb.AppendLine(JsonHelper.FormatJsonToString(JsonUtils.Serialize(temp)));
                    index++;
                }
                msg  = string.Format("Count:{0}/{1:D}\r\n", buffers.Length > count ? count : buffers.Length, buffers.Length);
                msg += sb.ToString();
            }
            else if (key.StartsWith("$"))
            {
                string[]      arr            = key.TrimStart(new char[] { '$' }).Split(new char[] { '_' });
                string        typeName       = arr[0];
                string        keyCode        = (arr.Length > 1) ? arr[1] : "";
                StringBuilder stringBuilder5 = new StringBuilder();
                if (string.IsNullOrEmpty(keyCode))
                {
                    byte[][] array10 = client.HKeys(key);
                    byte[][] array11 = client.HMGet(key, array10);
                    stringBuilder5.AppendFormat("¡¾{0}¡¿ Count:{1:D}", typeName, array10.Length);
                    stringBuilder5.AppendLine("");
                    int      num4   = 0;
                    byte[][] array2 = array10;
                    for (int i = 0; i < array2.Length; i++)
                    {
                        byte[]   bytes3       = array2[i];
                        string   arg          = "null";
                        Assembly dymincEntity = AppSetting.Current.Entity.DymincEntity;
                        if (dymincEntity != null)
                        {
                            Type type = dymincEntity.GetType(typeName, false, true);
                            try
                            {
                                byte[] data5 = array11[num4];
                                object obj   = ProtoBufUtils.Deserialize(data5, type);
                                if (obj != null)
                                {
                                    arg = JsonUtils.SerializeCustom(obj);
                                }
                            }
                            catch
                            {
                            }
                        }
                        stringBuilder5.AppendFormat("©»{0}\t{1}\t{2}", num4 + 1, Encoding.UTF8.GetString(bytes3), arg);
                        stringBuilder5.AppendLine();
                        num4++;
                    }
                }
                else
                {
                    stringBuilder5.AppendFormat("¡¾{0}¡¿Key:{1}", typeName, keyCode);
                    stringBuilder5.AppendLine("");
                    string   arg2          = "null";
                    Assembly dymincEntity2 = AppSetting.Current.Entity.DymincEntity;
                    if (dymincEntity2 != null)
                    {
                        Type type2 = dymincEntity2.GetType(typeName, false, true);
                        try
                        {
                            byte[] data6 = client.HGet("$" + typeName, Encoding.UTF8.GetBytes(keyCode));
                            object obj2  = ProtoBufUtils.Deserialize(data6, type2);
                            if (obj2 != null)
                            {
                                arg2 = JsonUtils.SerializeCustom(obj2);
                            }
                        }
                        catch
                        {
                        }
                    }
                    stringBuilder5.AppendFormat("Value:{0}", arg2);
                    stringBuilder5.AppendLine();
                }
                stringBuilder5.AppendLine("");
                msg = stringBuilder5.ToString();
            }
            else
            {
                string formatType   = AppSetting.DictTypeNameFormat;
                string typeName     = key.Split('_')[0];
                var    dymincEntity = AppSetting.Current.Entity.DymincEntity;
                if (dymincEntity == null)
                {
                    error = 102;
                    msg   = "Not generating entity assembly!";
                    return(false);
                }
                string asmName = dymincEntity.GetName().Name;
                string result  = "";
                var    buffer  = client.Get(key) ?? new byte[0];
                var    type    = dymincEntity.GetType(typeName, false, true);

                if (key.EndsWith(":remove"))
                {
                    //dictionary
                    var dictType = dymincEntity.GetType(string.Format(formatType, type.FullName, asmName));
                    var dict     = ProtoBufUtils.Deserialize(buffer, dictType);
                    result = JsonHelper.FormatJsonToString(JsonUtils.Serialize(dict));
                }
                else if ("String".Equals(typeName))
                {
                    result = Encoding.UTF8.GetString(buffer);
                }
                else
                {
                    var     refType   = Type.GetType(string.Format(formatType, type.FullName, asmName));
                    dynamic refObject = null;
                    try
                    {
                        refObject = ProtoBufUtils.Deserialize(buffer, refType);
                    }
                    catch
                    {
                    }
                    if (refObject != null)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine("Count:" + refObject.Count);
                        sb.AppendLine("[");
                        try
                        {
                            foreach (var pair in refObject)
                            {
                                object entity = pair.Value;
                                sb.AppendFormat("{0},", JsonHelper.FormatJsonToString(JsonUtils.Serialize(entity)));
                                sb.AppendLine();
                            }
                        }
                        catch (Exception er)
                        {
                            sb.AppendLine(er.Message);
                        }
                        sb.AppendLine("]");
                        result = sb.ToString();
                    }
                    else
                    {
                        refType = type;
                        try
                        {
                            refObject = ProtoBufUtils.Deserialize(buffer, refType);
                        }
                        catch
                        {
                        }
                        if (refObject != null)
                        {
                            result = JsonHelper.FormatJsonToString(JsonUtils.Serialize(refObject));
                        }
                        else
                        {
                            error = 100;
                            msg   = string.Format("Not found match type:{0} to deserialize.", typeName);
                            return(false);
                        }
                    }
                }
                msg = result;
            }
            return(true);
        }
示例#2
0
        private bool GetRedisKeyValue(RedisClient client, string key, out int error, out string msg)
        {
            error = 0;
            msg   = "";
            int count = 10;

            if (key.StartsWith("__GLOBAL_CHANGE_KEYS_NEW") || key.StartsWith("__QUEUE_REDIS_SYNC"))
            {
                byte[][]      keyBytes = client.HKeys(key);
                StringBuilder sb       = new StringBuilder();
                sb.AppendFormat("Count:{0:D}", keyBytes.Length);
                sb.AppendLine("[");
                foreach (var buffer in keyBytes)
                {
                    sb.AppendFormat("    {0}", Encoding.UTF8.GetString(buffer));
                    sb.AppendLine();
                }
                sb.AppendLine("]");
                msg = sb.ToString();
            }
            else if (key.StartsWith("__GLOBAL_CHANGE_KEYS"))
            {
                byte[][]      buffers = client.ZRange(key, 0, int.MaxValue);
                StringBuilder sb      = new StringBuilder();
                sb.AppendFormat("Count:{0:D}", buffers.Length);
                sb.AppendLine("[");
                foreach (var buffer in buffers)
                {
                    var temp = ProtoBufUtils.Deserialize <KeyValuePair <string, byte[]> >(buffer);
                    sb.AppendFormat("    {0}", temp.Key);
                    sb.AppendLine();
                }
                sb.AppendLine("]");
                msg = sb.ToString();
            }
            else if (key.StartsWith("__GLOBAL_SESSIONS"))
            {
                byte[] data = client.Get <byte[]>(key) ?? new byte[0];
                var    dict = ProtoBufUtils.Deserialize <ConcurrentDictionary <Guid, GameSession> >(data);
                msg  = "Count:" + dict.Count + "\r\n";
                msg += JsonHelper.FormatJsonToString(JsonUtils.Serialize(dict.Values.ToList()));
            }
            else if (key.StartsWith("__GLOBAL_SQL_CHANGE_KEYS_NEW") || key.StartsWith("__QUEUE_SQL_SYNC_WAIT"))
            {
                byte[][]      keyBytes = client.HKeys(key);
                StringBuilder sb       = new StringBuilder();
                sb.AppendLine("Count:" + keyBytes.Length);
                sb.AppendLine("[");
                foreach (var buffer in keyBytes)
                {
                    sb.AppendFormat("    {0}", Encoding.UTF8.GetString(buffer));
                    sb.AppendLine();
                }
                sb.AppendLine("]");
                msg = sb.ToString();
            }
            else if (key.StartsWith("__GLOBAL_SQL_CHANGE_KEYS"))
            {
                byte[] data = client.Get <byte[]>(key) ?? new byte[0];
                var    dict = ProtoBufUtils.Deserialize <Dictionary <string, bool> >(data) ??
                              new Dictionary <string, bool>();
                msg  = "Count:" + dict.Count + "\r\n";
                msg += JsonHelper.FormatJsonToString(JsonUtils.Serialize(dict.Keys.ToList()));
            }
            else if (key.StartsWith("EntityPrimaryKey_"))
            {
                var val = client.Get <long>(key);
                msg = string.Format("{0}:\t{1}", key, val);
            }
            else if (key.StartsWith("__GLOBAL_SQL_STATEMENT") || key.StartsWith("__QUEUE_SQL_SYNC"))
            {
                //sql
                StringBuilder sb      = new StringBuilder();
                byte[][]      buffers = client.ZRange(key, 0, int.MaxValue);
                int           index   = 0;
                foreach (var buffer in buffers)
                {
                    if (index >= count)
                    {
                        break;
                    }
                    var temp = ProtoBufUtils.Deserialize(buffer, typeof(SqlStatement));
                    sb.AppendLine(JsonHelper.FormatJsonToString(JsonUtils.Serialize(temp)));
                    index++;
                }
                msg  = string.Format("Count:{0}/{1:D}\r\n", buffers.Length > count ? count : buffers.Length, buffers.Length);
                msg += sb.ToString();
            }
            else if (key.StartsWith("$"))
            {
                byte[][]      keyBytes = client.HKeys(key);
                StringBuilder sb       = new StringBuilder();
                sb.AppendFormat("Count:{0:D}", keyBytes.Length);
                sb.AppendLine("[");
                foreach (var buffer in keyBytes)
                {
                    sb.AppendFormat("    {0}", Encoding.UTF8.GetString(buffer));
                    sb.AppendLine();
                }
                sb.AppendLine("]");
                msg = sb.ToString();
            }
            else
            {
                string formatType   = AppSetting.DictTypeNameFormat;
                string typeName     = key.Split('_')[0];
                var    dymincEntity = AppSetting.Current.Entity.DymincEntity;
                if (dymincEntity == null)
                {
                    error = 102;
                    msg   = "Not generating entity assembly!";
                    return(false);
                }
                string asmName = dymincEntity.GetName().Name;
                string result  = "";
                var    buffer  = client.Get(key) ?? new byte[0];
                var    type    = dymincEntity.GetType(typeName, false, true);

                if (key.EndsWith(":remove"))
                {
                    //dictionary
                    var dictType = dymincEntity.GetType(string.Format(formatType, type.FullName, asmName));
                    var dict     = ProtoBufUtils.Deserialize(buffer, dictType);
                    result = JsonHelper.FormatJsonToString(JsonUtils.Serialize(dict));
                }
                else if ("String".Equals(typeName))
                {
                    result = Encoding.UTF8.GetString(buffer);
                }
                else
                {
                    var     refType   = Type.GetType(string.Format(formatType, type.FullName, asmName));
                    dynamic refObject = null;
                    try
                    {
                        refObject = ProtoBufUtils.Deserialize(buffer, refType);
                    }
                    catch
                    {
                    }
                    if (refObject != null)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine("Count:" + refObject.Count);
                        sb.AppendLine("[");
                        try
                        {
                            foreach (var pair in refObject)
                            {
                                object entity = pair.Value;
                                sb.AppendFormat("{0},", JsonHelper.FormatJsonToString(JsonUtils.Serialize(entity)));
                                sb.AppendLine();
                            }
                        }
                        catch (Exception er)
                        {
                            sb.AppendLine(er.Message);
                        }
                        sb.AppendLine("]");
                        result = sb.ToString();
                    }
                    else
                    {
                        refType = type;
                        try
                        {
                            refObject = ProtoBufUtils.Deserialize(buffer, refType);
                        }
                        catch
                        {
                        }
                        if (refObject != null)
                        {
                            result = JsonHelper.FormatJsonToString(JsonUtils.Serialize(refObject));
                        }
                        else
                        {
                            error = 100;
                            msg   = string.Format("Not found match type:{0} to deserialize.", typeName);
                            return(false);
                        }
                    }
                }
                msg = result;
            }
            return(true);
        }