Example #1
0
        /// <summary>
        /// 保存一个对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="obj"></param>
        /// <param name="expiry"></param>
        /// <returns></returns>
        public bool StringSet <T>(string key, T obj, TimeSpan?expiry = default(TimeSpan?))
        {
            key = AddSysCustomKey(key);
            string json = JsonNetHelper.SerializeObject(obj);

            return(Connection(db => db.StringSet(key, json, expiry)));
        }
Example #2
0
        /// <summary>
        /// 保存一个对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="obj"></param>
        /// <param name="expiry"></param>
        /// <returns></returns>
        public async Task <bool> StringSetAsync <T>(string key, T obj, TimeSpan?expiry = default(TimeSpan?))
        {
            key = AddSysCustomKey(key);
            string json = JsonNetHelper.SerializeObject(obj);

            return(await Connection(db => db.StringSetAsync(key, json, expiry)));
        }
Example #3
0
 /// <summary>
 /// 存储数据到hash表
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key"></param>
 /// <param name="dataKey"></param>
 /// <param name="t"></param>
 /// <returns></returns>
 public async Task <bool> HashSetAsync <T>(string key, string dataKey, T t)
 {
     key = AddSysCustomKey(key);
     return(await Connection(db =>
     {
         string json = JsonNetHelper.SerializeObject(t);
         return db.HashSetAsync(key, dataKey, json);
     }));
 }
Example #4
0
 /// <summary>
 /// 存储数据到hash表
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key"></param>
 /// <param name="dataKey"></param>
 /// <param name="t"></param>
 /// <returns></returns>
 public bool HashSet <T>(string key, string dataKey, T t)
 {
     key = AddSysCustomKey(key);
     return(Connection(db =>
     {
         string json = JsonNetHelper.SerializeObject(t);
         return db.HashSet(key, dataKey, json);
     }));
 }
Example #5
0
 /// <summary>
 /// 设置Session对象
 /// </summary>
 /// <param name="session"></param>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public static void Set <T>(this ISession session, string key, T value)
 {
     session.SetString(key, JsonNetHelper.SerializeObject(value));
 }
Example #6
0
        /// <summary>
        /// Redis发布订阅  发布
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="channel"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public long Publish <T>(string channel, T msg)
        {
            ISubscriber sub = _conn.GetSubscriber();

            return(sub.Publish(channel, JsonNetHelper.SerializeObject(msg)));
        }
Example #7
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public async Task <bool> SortedSetRemoveAsync <T>(string key, T value)
 {
     key = AddSysCustomKey(key);
     return(await Connection(redis => redis.SortedSetRemoveAsync(key, JsonNetHelper.SerializeObject(value))));
 }
Example #8
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public bool SortedSetRemove <T>(string key, T value)
 {
     key = AddSysCustomKey(key);
     return(Connection(redis => redis.SortedSetRemove(key, JsonNetHelper.SerializeObject(value))));
 }
Example #9
0
 /// <summary>
 /// 入栈
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public async Task <long> ListLeftPushAsync <T>(string key, T value)
 {
     key = AddSysCustomKey(key);
     return(await Connection(db => db.ListLeftPushAsync(key, JsonNetHelper.SerializeObject(value))));
 }
Example #10
0
 /// <summary>
 /// 入栈
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public void ListLeftPush <T>(string key, T value)
 {
     key = AddSysCustomKey(key);
     Connection(db => db.ListLeftPush(key, JsonNetHelper.SerializeObject(value)));
 }