Ejemplo n.º 1
0
        /// <summary>
        /// 普通Model Hash
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="modelKey"></param>
        /// <returns></returns>
        public static T GetHash <T>(string modelKey) where T : new()
        {
            var dics = redis.HGetAll(modelKey);

            if (dics == null || dics.Count <= 0)
            {
                return(default);
Ejemplo n.º 2
0
        /// <summary>
        /// get value by key
        /// </summary>
        /// <param name="KeyName"></param>
        /// <returns></returns>
        public Dictionary <String, T> GetHashValue <T>(String KeyName)
        {
            if (conn == null)
            {
                throw new Exception("Connection has not initialize.");
            }

            return(conn.HGetAll <T>(KeyName));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 获取指定key中所有字段
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static Dictionary <string, string> GetHashAll(string key)
 {
     try
     {
         return(_redisManager.HGetAll(key));
     }
     catch (Exception)
     {
         return(new Dictionary <string, string>());
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取整个hash的数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="hashId"></param>
        /// <returns></returns>
        public List <T> GetHashAll <T>(string hashId)
        {
            var result  = new List <T>();
            var result1 = csredis.HGetAll(hashId);

            foreach (var item in result1)
            {
                var model = ConvertObj <T>(item.Value);
                result.Add(model);
            }
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 负载分区规则:取SessionId后四位字符,
        /// 转成10进制数字0-65535,求模
        /// </summary>
        /// <param name="SessionId">客户端id</param>
        /// <returns></returns>
        protected string SelectServer(Guid SessionId)
        {
            string OnLineServerKey = RedisKeyFormatUtil.GetOnLineServerKey(_appId);
            var    ret             = _redis.HGetAll <string>(OnLineServerKey);

            if (ret == null || ret.Count == 0)
            {
                throw new WebSocketException((int)WebSocketErrorCodeType.ServiceNotStart, WebSocketErrorCodeType.ServiceNotStart.ToString());
            }
            _servers = ret.Values.ToList();
            var servers_idx = int.Parse(SessionId.ToString("N").Substring(28), NumberStyles.HexNumber) % _servers.Count;

            if (servers_idx >= _servers.Count)
            {
                servers_idx = 0;
            }
            return(_servers[servers_idx]);
        }
 public override void Load()
 {
     Data = _redisClient.HGetAll <string>(_options.HashCacheKey) ?? new Dictionary <string, string>();
 }
Ejemplo n.º 7
0
 /// <summary>
 ///  获取在哈希表中指定 key 的所有字段和值
 /// </summary>
 public Dictionary <string, T> HashGetAll <T>(string key)
 {
     return(_redisClient.HGetAll <T>(key));
 }