/// <summary> /// 滑动过期设置 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cache"></param> /// <param name="key"></param> /// <param name="field"></param> /// <param name="value"></param> /// <param name="slidingExpirationSec"></param> /// <returns></returns> public static bool HSet <T>(this IRedisCache cache, string key, string field, T value, int slidingExpirationSec) { return(cache.HSet(key, field, value, new CacheItemOptions { SlidingExpiration = new TimeSpan(0, 0, slidingExpirationSec) }));; }
/// <summary> /// 绝对过期设置 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cache"></param> /// <param name="key"></param> /// <param name="field"></param> /// <param name="value"></param> /// <param name="absoluteExpiration"></param> /// <returns></returns> public static bool HSet <T>(this IRedisCache cache, string key, string field, T value, DateTimeOffset absoluteExpiration) { return(cache.HSet(key, field, value, new CacheItemOptions { AbsoluteExpiration = absoluteExpiration })); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cache"></param> /// <param name="key"></param> /// <param name="field"></param> /// <param name="value"></param> /// <param name="absoluteExpirationRelativeToNow"></param> /// <returns></returns> public static bool HSet <T>(this IRedisCache cache, string key, string field, T value, TimeSpan absoluteExpirationRelativeToNow) { return(cache.HSet(key, field, value, new CacheItemOptions { AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow })); }
public static void HashSetTest(IRedisCache redisCache) { var res = redisCache.KeyDelete("TestHashID"); for (int i = 0; i < 100; i++) { if (i == 78) { redisCache.HSet("TestHashID", "78", ""); } else { redisCache.HSet("TestHashID", i.ToString(), i.ToString()); } } }