Exemple #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)));
        }
Exemple #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)));
        }
Exemple #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);
     }));
 }
Exemple #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);
     }));
 }
Exemple #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));
 }
Exemple #6
0
        /// <summary>
        /// 读取Session对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="session"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static T Get <T>(this ISession session, string key)
        {
            var value = session.GetString(key);

            return(value == null ? default(T) : JsonNetHelper.DeserializeObject <T>(value));
        }
Exemple #7
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)));
        }
Exemple #8
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))));
 }
Exemple #9
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))));
 }
Exemple #10
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))));
 }
Exemple #11
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)));
 }