예제 #1
0
        /// <summary>
        /// 获取hashtable中所有key的value
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public List <T> HashGetAllKey <T>(string key)
        {
            var aaa    = GetDatabase().HashGetAll(MergeKey(key));
            var values = GetDatabase().HashGetAll(MergeKey(key)).Select(x => x.Name);

            return(values.Select(i => RedisUtility.ConvertToEntity <T>(i)).ToList());
        }
예제 #2
0
 /// <summary>
 /// 以对象方式存储
 /// </summary>
 /// <typeparam name="T">实体</typeparam>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="expiry">过期时间</param>
 /// <returns></returns>
 public bool Set <T>(string key, T value, TimeSpan?expiry = default(TimeSpan?))
 {
     return(GetDatabase().StringSet(MergeKey(key), RedisUtility.ConvertToStr(value), expiry));
 }
예제 #3
0
 /// <summary>
 /// 根据key和field获取指定类型数据(异步)
 /// </summary>
 /// <param name="dbNum">数据库号码</param>
 /// <param name="key">键</param>
 /// <param name="field">域</param>
 /// <returns></returns>
 public async Task <T> GetHashAsync <T>(int dbNum, string key, string field)
 {
     return(RedisUtility.ConvertToEntity <T>(await GetDatabase(dbNum).HashGetAsync(MergeKey(key), field)));
 }
예제 #4
0
 /// <summary>
 /// 存储指定类型数据(异步)
 /// </summary>
 /// <param name="dbNum">数据库号码</param>
 /// <param name="key">键</param>
 /// <param name="field">域</param>
 /// <param name="value">值</param>
 /// <returns></returns>
 public async Task <bool> SetHashAsync <T>(int dbNum, string key, string field, T value)
 {
     return(await GetDatabase(dbNum).HashSetAsync(MergeKey(key), field, RedisUtility.ConvertToStr(value)));
 }
예제 #5
0
        /// <summary>
        /// 获取所有hashtable中的值(异步)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public async Task <List <T> > HashGetAllAsync <T>(string key)
        {
            var values = (await GetDatabase().HashGetAllAsync(MergeKey(key))).Select(x => x.Value);

            return(values.Select(i => RedisUtility.ConvertToEntity <T>(i)).ToList());
        }
예제 #6
0
        /// <summary>
        /// 根据key获取指定类型所有数据列表(value必须为同一类型)
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="dbNum">数据库号码</param>
        /// <param name="keys">键</param>
        /// <returns></returns>
        public async Task <List <T> > GetHashAllAsync <T>(int dbNum, string key)
        {
            var values = await GetDatabase(dbNum).HashGetAllAsync(MergeKey(key));

            return(values.Select(i => RedisUtility.ConvertToEntity <T>(i.Value)).ToList());
        }
예제 #7
0
        /// <summary>
        /// 根据key和fields获取指定类型数据列表(value必须为同一类型)
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="dbNum">数据库号码</param>
        /// <param name="keys">键</param>
        /// <returns></returns>
        public async Task <List <T> > GetHashListAsync <T>(int dbNum, string key, List <string> fields)
        {
            var values = await GetDatabase(dbNum).HashGetAsync(MergeKey(key), ConvertRedisFields(fields));

            return(values.Select(i => RedisUtility.ConvertToEntity <T>(i)).ToList());
        }
예제 #8
0
        /// <summary>
        /// 根据key和fields获取指定类型数据列表(value必须为同一类型)
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="keys">键列表</param>
        /// <returns></returns>
        public List <T> GetHashList <T>(string key, List <string> fields)
        {
            var values = GetDatabase().HashGet(MergeKey(key), ConvertRedisFields(fields));

            return(values.Select(i => RedisUtility.ConvertToEntity <T>(i)).ToList());
        }
예제 #9
0
        /// <summary>
        /// 根据key获取指定类型所有数据列表(value必须为同一类型)
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="dbNum">数据库号码</param>
        /// <param name="keys">键</param>
        /// <returns></returns>
        public List <T> GetHashAll <T>(int dbNum, string key)
        {
            var values = GetDatabase(dbNum).HashGetAll(MergeKey(key));

            return(values.Select(i => RedisUtility.ConvertToEntity <T>(i.Value)).ToList());
        }
예제 #10
0
 /// <summary>
 /// 存储指定类型数据
 /// </summary>
 /// <param name="dbNum">数据库号码</param>
 /// <param name="key">键</param>
 /// <param name="field">域</param>
 /// <param name="value">值</param>
 /// <param name="expiry">过期时间</param>
 /// <returns></returns>
 public bool SetHash <T>(int dbNum, string key, string field, T value, TimeSpan expiry)
 {
     GetDatabase(dbNum).HashSet(MergeKey(key), field, RedisUtility.ConvertToStr(value));
     return(GetDatabase().KeyExpire(MergeKey(key), expiry));
 }
예제 #11
0
 /// <summary>
 /// 根据key和field获取指定类型数据
 /// </summary>
 /// <param name="dbNum">数据库号码</param>
 /// <param name="key">键</param>
 /// <param name="field">域</param>
 /// <returns></returns>
 public T GetHash <T>(int dbNum, string key, string field)
 {
     return(RedisUtility.ConvertToEntity <T>(GetDatabase(dbNum).HashGet(MergeKey(key), field)));
 }
예제 #12
0
 /// <summary>
 /// 存储指定类型数据
 /// </summary>
 /// <param name="dbNum">数据库号码</param>
 /// <param name="key">键</param>
 /// <param name="field">域</param>
 /// <param name="value">值</param>
 /// <returns></returns>
 public bool SetHash <T>(int dbNum, string key, string field, T value)
 {
     return(GetDatabase(dbNum).HashSet(MergeKey(key), field, RedisUtility.ConvertToStr(value)));
 }
예제 #13
0
 /// <summary>
 /// 根据key获取对象方式存储的数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="dbNum">数据库号码</param>
 /// <param name="key">键</param>
 /// <returns></returns>
 public async Task <T> GetAsync <T>(int dbNum, string key)
 {
     return(RedisUtility.ConvertToEntity <T>(await GetDatabase(dbNum).StringGetAsync(MergeKey(key))));
 }
예제 #14
0
 /// <summary>
 /// 以对象方式存储(异步)
 /// </summary>
 /// <typeparam name="T">实体</typeparam>
 /// <param name="dbNum">数据库号码</param>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="expiry">过期时间</param>
 /// <returns></returns>
 public async Task <bool> SetAsync <T>(int dbNum, string key, T value, TimeSpan?expiry = default(TimeSpan?))
 {
     return(await GetDatabase(dbNum).StringSetAsync(MergeKey(key), RedisUtility.ConvertToStr(value), expiry));
 }
예제 #15
0
        /// <summary>
        /// 根据keys列表获取对象方式存储的数据
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="dbNum">数据库号码</param>
        /// <param name="keys">键</param>
        /// <returns></returns>
        public List <T> GetList <T>(int dbNum, List <string> keys)
        {
            var values = GetDatabase(dbNum).StringGet(ConvertRedisKeys(keys));

            return(values.Select(i => RedisUtility.ConvertToEntity <T>(i)).ToList());
        }
예제 #16
0
 /// <summary>
 /// 根据key获取对象方式存储的数据
 /// </summary>
 /// <typeparam name="T">实体</typeparam>
 /// <param name="dbNum">数据库号码</param>
 /// <param name="key">键</param>
 /// <returns></returns>
 public T Get <T>(int dbNum, string key)
 {
     return(RedisUtility.ConvertToEntity <T>(GetDatabase(dbNum).StringGet(MergeKey(key))));
 }