/// <summary>执行命令</summary> /// <typeparam name="T"></typeparam> /// <param name="func"></param> /// <returns></returns> public virtual T Execute <T>(Func <RedisClient, T> func) { using (var pi = Pool.AcquireItem()) { return(func(pi.Value)); } }
/// <summary>访问地址获取字符串</summary> /// <param name="address"></param> /// <returns></returns> public static async Task <String> GetStringAsync(String address) { using (var pi = Pool.AcquireItem()) { return(await pi.Value.DownloadStringAsync(address)); } }
/// <summary>执行命令</summary> /// <typeparam name="T"></typeparam> /// <param name="func"></param> /// <returns></returns> public virtual T Execute <T>(Func <RedisClient, T> func) { using (var pi = Pool.AcquireItem()) { var i = 0; do { try { var rs = func(pi.Value); // 如果返回Packet,需要在离开对象池之前拷贝,否则可能出现冲突 if ((Object)rs is Packet pk) { return((T)(Object)pk.Clone()); } return(rs); } catch (InvalidDataException) { if (i++ >= Retry) { throw; } } } while (true); } }
/// <summary>执行命令</summary> /// <typeparam name="T"></typeparam> /// <param name="func"></param> /// <returns></returns> public virtual T Execute<T>(Func<RedisClient, T> func) { using (var pi = Pool.AcquireItem()) { var i = 0; do { try { return func(pi.Value); } catch (InvalidDataException) { if (i++ >= Retry) throw; } } while (true); } }