mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 15:43:27 +08:00
【调整】优化redis仓储,实现LockTake/LockRelease锁处理并发问题。
This commit is contained in:
@@ -10,21 +10,110 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IRedisOperationRepository
|
public interface IRedisOperationRepository
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 延长锁(续约)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="cacheTime"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool LockExtend(string key, string value, TimeSpan cacheTime);
|
||||||
|
|
||||||
//获取 Reids 缓存值
|
/// <summary>
|
||||||
|
/// 延长锁(续约)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="cacheTime"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> LockExtendAsync(string key, string value, TimeSpan cacheTime);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 释放锁
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool LockRelease(string key, string value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 释放锁
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> LockReleaseAsync(string key, string value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取锁
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="cacheTime"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool LockTake(string key, string value, TimeSpan cacheTime);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取锁
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="cacheTime"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Task<bool> LockTakeAsync(string key, string value, TimeSpan cacheTime);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取值
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task<string> Get(string key);
|
Task<string> Get(string key);
|
||||||
|
|
||||||
|
RedisValue StringGet(string key);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 搜索获取匹配Key
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pattern"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
List<string> SearchKey(string pattern);
|
||||||
|
|
||||||
//获取值,并序列化
|
//获取值,并序列化
|
||||||
Task<TEntity> Get<TEntity>(string key);
|
Task<TEntity> Get<TEntity>(string key);
|
||||||
|
|
||||||
//保存
|
//保存
|
||||||
Task Set(string key, object value, TimeSpan cacheTime);
|
Task<bool> StringSetAsync(string key, string value, TimeSpan cacheTime);
|
||||||
|
|
||||||
|
bool StringSet(string key, string value, TimeSpan cacheTime);
|
||||||
|
|
||||||
|
bool StringSet(string key, string value);
|
||||||
|
|
||||||
|
bool StringSet(string key, RedisValue value);
|
||||||
|
|
||||||
|
bool StringSet(string key, RedisValue value, TimeSpan cacheTime);
|
||||||
|
|
||||||
|
|
||||||
|
Task SetAsync(string key, object value, TimeSpan cacheTime);
|
||||||
|
|
||||||
|
Task<long> StringIncrement(string key, long value=1);
|
||||||
|
|
||||||
|
|
||||||
//判断是否存在
|
//判断是否存在
|
||||||
Task<bool> Exist(string key);
|
Task<bool> KeyExistsAsync(string key);
|
||||||
|
|
||||||
|
bool KeyExists(string key);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取键 过期时间
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<TimeSpan?> KeyTime(string key);
|
||||||
|
|
||||||
//移除某一个缓存值
|
//移除某一个缓存值
|
||||||
Task Remove(string key);
|
Task KeyDeleteAsync(string key);
|
||||||
|
void KeyDelete(string key);
|
||||||
|
|
||||||
//全部清除
|
//全部清除
|
||||||
Task Clear();
|
Task Clear();
|
||||||
@@ -131,26 +220,46 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
|||||||
Task ListClearAsync(string redisKey);
|
Task ListClearAsync(string redisKey);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 有序集合/定时任务延迟队列用的多(直接传分钟)
|
/// 有序集合/定时任务延迟队列用的多
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="redisKey">key</param>
|
/// <param name="redisKey">key</param>
|
||||||
/// <param name="redisValue">元素</param>
|
/// <param name="redisValue">元素</param>
|
||||||
/// <param name="score">分数</param>
|
/// <param name="score">分数</param>
|
||||||
Task SortedSetAddAsync(string redisKey, string redisValue, double score);
|
Task<bool> SortedSetAddAsync(string redisKey, string redisValue, double score);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 有序集合/定时任务延迟队列用的多(直接传时间)
|
/// 插入zset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="redisKey">key</param>
|
/// <param name="key">key</param>
|
||||||
/// <param name="redisValue">元素</param>
|
/// <param name="msg">消息</param>
|
||||||
/// <param name="dt">时间</param>
|
/// <param name="time">延迟执行时间</param>
|
||||||
Task SortedSetAddAsync(string redisKey, string redisValue, DateTime dt);
|
/// <returns></returns>
|
||||||
|
Task<bool> SortedSetAddAsync(string key, string msg, DateTime time);
|
||||||
|
|
||||||
#region 会员陌小北(QQ:1078350533) 添加的 几个有序集合功能
|
/// <summary>
|
||||||
|
/// 返回有序集合中指定成员的索引
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<long?> SortedSetRankAsync(string key, string value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 返回有序集合中的分数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<double?> SortedSetScoreAsync(string key, string value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 返回有序集合中的分数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
double? SortedSetScore(string key, string value);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 返回有序列表里的数据
|
/// 返回有序列表里的数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -170,6 +279,7 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
|||||||
Task<long> SortedSetRemoveRangeByRankAsync(string redisKey, int start, int stop);
|
Task<long> SortedSetRemoveRangeByRankAsync(string redisKey, int start, int stop);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 返回有序列表里的指定范围数量
|
/// 返回有序列表里的指定范围数量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -177,9 +287,9 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
|||||||
/// <param name="start">0 是第一个</param>
|
/// <param name="start">0 是第一个</param>
|
||||||
/// <param name="stop">最大分数值</param>
|
/// <param name="stop">最大分数值</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<long> SortedSetLengthAsync(string redisKey, int start, int stop);
|
Task<long> SortedSetLengthAsync(string redisKey, long min, long max);
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
|
|
||||||
|
|
||||||
namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
||||||
{
|
{
|
||||||
public class RedisOperationRepository : IRedisOperationRepository
|
public class RedisOperationRepository : IRedisOperationRepository
|
||||||
@@ -39,22 +40,162 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> Exist(string key)
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取锁
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="cacheTime"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool LockTake(string key, string value, TimeSpan cacheTime)
|
||||||
{
|
{
|
||||||
|
return _database.LockTake(key, value, cacheTime);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步获取锁
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="cacheTime"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> LockTakeAsync(string key, string value, TimeSpan cacheTime)
|
||||||
|
{
|
||||||
|
return await _database.LockTakeAsync(key, value, cacheTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 延长锁(续约)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="cacheTime"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
|
||||||
|
public bool LockExtend(string key, string value, TimeSpan cacheTime)
|
||||||
|
{
|
||||||
|
return _database.LockExtend(key, value, cacheTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 延长锁(续约)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="cacheTime"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
|
||||||
|
public async Task<bool> LockExtendAsync(string key, string value, TimeSpan cacheTime)
|
||||||
|
{
|
||||||
|
return await _database.LockExtendAsync(key, value, cacheTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 释放锁
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool LockRelease(string key, string value)
|
||||||
|
{
|
||||||
|
return _database.LockRelease(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步释放锁
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> LockReleaseAsync(string key, string value)
|
||||||
|
{
|
||||||
|
return await _database.LockReleaseAsync(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判断key是否存在
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> KeyExistsAsync(string key)
|
||||||
|
{
|
||||||
|
|
||||||
return await _database.KeyExistsAsync(key);
|
return await _database.KeyExistsAsync(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判断key是否存在
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool KeyExists(string key)
|
||||||
|
{
|
||||||
|
|
||||||
|
return _database.KeyExists(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取键过期时间
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TimeSpan?> KeyTime(string key)
|
||||||
|
{
|
||||||
|
|
||||||
|
return await _database.KeyTimeToLiveAsync(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<string> Get(string key)
|
public async Task<string> Get(string key)
|
||||||
{
|
{
|
||||||
return await _database.StringGetAsync(key);
|
return await _database.StringGetAsync(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Remove(string key)
|
public RedisValue StringGet(string key)
|
||||||
|
{
|
||||||
|
return _database.StringGet(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 搜索匹配Key
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pattern"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<string> SearchKey(string pattern)
|
||||||
|
{
|
||||||
|
|
||||||
|
var list = new List<string>();
|
||||||
|
var script = "return redis.call('keys',@pattern)";
|
||||||
|
var prepared = LuaScript.Prepare(script);
|
||||||
|
var redisResult = _database.ScriptEvaluate(prepared, new { pattern });
|
||||||
|
if (!redisResult.IsNull)
|
||||||
|
{
|
||||||
|
foreach (var key in (RedisKey[])redisResult)
|
||||||
|
{
|
||||||
|
|
||||||
|
list.Add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task KeyDeleteAsync(string key)
|
||||||
{
|
{
|
||||||
await _database.KeyDeleteAsync(key);
|
await _database.KeyDeleteAsync(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Set(string key, object value, TimeSpan cacheTime)
|
public void KeyDelete(string key)
|
||||||
|
{
|
||||||
|
_database.KeyDelete(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task SetAsync(string key, object value, TimeSpan cacheTime)
|
||||||
{
|
{
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
@@ -63,6 +204,65 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<bool> StringSetAsync(string key, string value, TimeSpan cacheTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
return await _database.StringSetAsync(key, value, cacheTime);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public bool StringSet(string key, string value, TimeSpan cacheTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
return _database.StringSet(key, value, cacheTime);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool StringSet(string key, string value)
|
||||||
|
{
|
||||||
|
|
||||||
|
return _database.StringSet(key, value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool StringSet(string key, RedisValue value, TimeSpan cacheTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
return _database.StringSet(key, value, cacheTime);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool StringSet(string key, RedisValue value)
|
||||||
|
{
|
||||||
|
|
||||||
|
return _database.StringSet(key, value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Increment 递增
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<long> StringIncrement(string key, long value=1)
|
||||||
|
{
|
||||||
|
|
||||||
|
return await _database.StringIncrementAsync(key, value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<TEntity> Get<TEntity>(string key)
|
public async Task<TEntity> Get<TEntity>(string key)
|
||||||
{
|
{
|
||||||
var value = await _database.StringGetAsync(key);
|
var value = await _database.StringGetAsync(key);
|
||||||
@@ -77,6 +277,9 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据key获取RedisValue
|
/// 根据key获取RedisValue
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -229,29 +432,70 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 有序集合/定时任务延迟队列用的多(直接传分钟)
|
/// 有序集合/定时任务延迟队列用的多
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="redisKey">key</param>
|
/// <param name="redisKey">key</param>
|
||||||
/// <param name="redisValue">元素</param>
|
/// <param name="redisValue">元素</param>
|
||||||
/// <param name="score">分数</param>
|
/// <param name="score">分数</param>
|
||||||
public async Task SortedSetAddAsync(string redisKey, string redisValue, double score)
|
public async Task<bool> SortedSetAddAsync(string redisKey, string redisValue, double score)
|
||||||
{
|
{
|
||||||
await _database.SortedSetAddAsync(redisKey, redisValue, score);
|
return await _database.SortedSetAddAsync(redisKey, redisValue, score);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 有序集合/定时任务延迟队列用的多(直接传时间)
|
/// 添加到有序集合 用时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="redisKey">key</param>
|
/// <param name="key"></param>
|
||||||
/// <param name="redisValue">元素</param>
|
/// <param name="msg"></param>
|
||||||
/// <param name="dt">时间</param>
|
/// <param name="time"></param>
|
||||||
public async Task SortedSetAddAsync(string redisKey, string redisValue, DateTime dt)
|
/// <returns></returns>
|
||||||
|
|
||||||
|
public async Task<bool> SortedSetAddAsync(string key, string msg, DateTime time)
|
||||||
{
|
{
|
||||||
var score = (dt.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
|
var score = (time.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
|
||||||
await _database.SortedSetAddAsync(redisKey, redisValue, score);
|
var bl = await _database.SortedSetAddAsync(key, msg, score);
|
||||||
|
//When.NotExists 不更新 直接添加
|
||||||
|
return bl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region 小北 添加的 几个有序集合功能
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取有序集合索引
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<long?> SortedSetRankAsync(string key, string value)
|
||||||
|
{
|
||||||
|
var result= await _database.SortedSetRankAsync(key,value);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 返回有序集中,成员的分数值。 如果成员元素不是有序集 key 的成员,或 key 不存在,返回 null
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<double?> SortedSetScoreAsync(string key, string value)
|
||||||
|
{
|
||||||
|
var result = await _database.SortedSetScoreAsync(key, value);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public double? SortedSetScore(string key, string value)
|
||||||
|
{
|
||||||
|
var result = _database.SortedSetScore(key, value);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 会员陌小北(QQ:1078350533) 添加的 几个有序集合功能
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 返回有序列表里的数据
|
/// 返回有序列表里的数据
|
||||||
@@ -262,12 +506,16 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<IEnumerable<string>> SortedSetRangeByRankAsync(string redisKey, int start, int stop)
|
public async Task<IEnumerable<string>> SortedSetRangeByRankAsync(string redisKey, int start, int stop)
|
||||||
{
|
{
|
||||||
var result = await _database.SortedSetRangeByRankAsync(redisKey, start, stop);
|
var result= await _database.SortedSetRangeByRankAsync(redisKey, start, stop);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return result.Select(o => o.ToString());
|
return result.Select(o => o.ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 移出序列表里的指定范围数量
|
/// 移出序列表里的指定范围数量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -275,7 +523,7 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
|||||||
/// <param name="start">0 是第一个</param>
|
/// <param name="start">0 是第一个</param>
|
||||||
/// <param name="stop">最大分数值</param>
|
/// <param name="stop">最大分数值</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<long> SortedSetRemoveRangeByRankAsync(string redisKey, int start, int stop)
|
public async Task<long> SortedSetRemoveRangeByRankAsync(string redisKey, int start, int stop)
|
||||||
{
|
{
|
||||||
return await _database.SortedSetRemoveRangeByRankAsync(redisKey, start, stop);
|
return await _database.SortedSetRemoveRangeByRankAsync(redisKey, start, stop);
|
||||||
}
|
}
|
||||||
@@ -287,13 +535,12 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
|
|||||||
/// <param name="start">0 是第一个</param>
|
/// <param name="start">0 是第一个</param>
|
||||||
/// <param name="stop">最大分数值</param>
|
/// <param name="stop">最大分数值</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<long> SortedSetLengthAsync(string redisKey, int start, int stop)
|
public async Task<long> SortedSetLengthAsync(string redisKey, long min, long max)
|
||||||
{
|
{
|
||||||
return await _database.SortedSetLengthAsync(redisKey, start, stop);
|
return await _database.SortedSetLengthAsync(redisKey, min, max);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion 会员陌小北(QQ:1078350533) 添加的 几个有序集合功能
|
#endregion 小北 添加的 几个有序集合功能
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ namespace CoreCms.Net.Core.AOP
|
|||||||
}
|
}
|
||||||
response ??= string.Empty;
|
response ??= string.Empty;
|
||||||
|
|
||||||
_cache.Set(cacheKey, response, TimeSpan.FromMinutes(qCachingAttribute.AbsoluteExpiration)).Wait();
|
_cache.SetAsync(cacheKey, response, TimeSpan.FromMinutes(qCachingAttribute.AbsoluteExpiration)).Wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ namespace CoreCms.Net.Task
|
|||||||
entity.updateTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
|
entity.updateTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
|
||||||
await _weChatAccessTokenServices.UpdateAsync(entity);
|
await _weChatAccessTokenServices.UpdateAsync(entity);
|
||||||
}
|
}
|
||||||
await _redisOperationRepository.Set(GlobalEnumVars.AccessTokenEnum.WeiXinAccessToken.ToString(), entity, TimeSpan.FromMinutes(120));
|
await _redisOperationRepository.SetAsync(GlobalEnumVars.AccessTokenEnum.WeiXinAccessToken.ToString(), entity, TimeSpan.FromMinutes(120));
|
||||||
|
|
||||||
//插入日志
|
//插入日志
|
||||||
var model = new SysTaskLog
|
var model = new SysTaskLog
|
||||||
@@ -162,7 +162,7 @@ namespace CoreCms.Net.Task
|
|||||||
await _weChatAccessTokenServices.UpdateAsync(entity);
|
await _weChatAccessTokenServices.UpdateAsync(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
await _redisOperationRepository.Set(
|
await _redisOperationRepository.SetAsync(
|
||||||
GlobalEnumVars.AccessTokenEnum.WxOpenAccessToken.ToString(), entity,
|
GlobalEnumVars.AccessTokenEnum.WxOpenAccessToken.ToString(), entity,
|
||||||
TimeSpan.FromMinutes(120));
|
TimeSpan.FromMinutes(120));
|
||||||
|
|
||||||
|
|||||||
@@ -14,16 +14,16 @@
|
|||||||
"PassWord": "CoreShopProfessional"
|
"PassWord": "CoreShopProfessional"
|
||||||
},
|
},
|
||||||
"AppConfig": {
|
"AppConfig": {
|
||||||
"AppUrl": "https://admin.pro.coreshop.cn/", //后端管理地址
|
"AppUrl": "https://admin.test.pro.coreshop.cn/", //后端管理地址
|
||||||
"AppInterFaceUrl": "https://api.pro.coreshop.cn/", //接口请求地址
|
"AppInterFaceUrl": "https://api.test.pro.coreshop.cn/", //接口请求地址
|
||||||
"AppVersion": "CoreShopProfessional v0.5.5"
|
"AppVersion": "CoreShopProfessional v0.6.0"
|
||||||
},
|
},
|
||||||
//redis为必须启动项,请保持redis为正常可用
|
//redis为必须启动项,请保持redis为正常可用
|
||||||
"RedisConfig": {
|
"RedisConfig": {
|
||||||
"UseCache": true, //启用redis作为内存选择
|
"UseCache": true, //启用redis作为内存选择
|
||||||
"UseTimedTask": true, //启用redis作为定时任务
|
"UseTimedTask": true, //启用redis作为定时任务
|
||||||
// 如果采用容器化部署Service 要写成redis的服务名,否则写地址
|
// 如果采用容器化部署Service 要写成redis的服务名,否则写地址
|
||||||
"ConnectionString": "127.0.0.1:6379,password=CoreShop,connectTimeout=3000,connectRetry=1,syncTimeout=10000,DefaultDatabase=9,abortConnect=false" //redis数据库连接字符串
|
"ConnectionString": "127.0.0.1:6379,password=coreshop,connectTimeout=30000,responseTimeout=30000,abortConnect=false,connectRetry=1,syncTimeout=10000,DefaultDatabase=9" //redis数据库连接字符串
|
||||||
},
|
},
|
||||||
//jwt授权认证的一些设置
|
//jwt授权认证的一些设置
|
||||||
"JwtConfig": {
|
"JwtConfig": {
|
||||||
@@ -220,11 +220,11 @@
|
|||||||
},
|
},
|
||||||
"PayCallBack": {
|
"PayCallBack": {
|
||||||
//微信支付回调
|
//微信支付回调
|
||||||
"WeChatPayUrl": "https://api.pro.coreshop.cn/Notify/WeChatPay/Unifiedorder",
|
"WeChatPayUrl": "https://api.test.pro.coreshop.cn/Notify/WeChatPay/Unifiedorder",
|
||||||
//微信退款回调
|
//微信退款回调
|
||||||
"WeChatRefundUrl": "https://api.pro.coreshop.cn/Notify/WeChatPay/Refund",
|
"WeChatRefundUrl": "https://api.test.pro.coreshop.cn/Notify/WeChatPay/Refund",
|
||||||
//支付宝支付回调
|
//支付宝支付回调
|
||||||
"AlipayUrl": "https://api.pro.coreshop.cn/Notify/AliPay/Unifiedorder",
|
"AlipayUrl": "https://api.test.pro.coreshop.cn/Notify/AliPay/Unifiedorder",
|
||||||
//支付宝退款回调
|
//支付宝退款回调
|
||||||
"AlipayRefundUrl": ""
|
"AlipayRefundUrl": ""
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CoreCms.Net.Auth.HttpContextUser;
|
using CoreCms.Net.Auth.HttpContextUser;
|
||||||
|
using CoreCms.Net.Caching.AutoMate.RedisCache;
|
||||||
using CoreCms.Net.Configuration;
|
using CoreCms.Net.Configuration;
|
||||||
using CoreCms.Net.IServices;
|
using CoreCms.Net.IServices;
|
||||||
using CoreCms.Net.Model.Entities;
|
using CoreCms.Net.Model.Entities;
|
||||||
@@ -47,6 +48,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||||||
private readonly ICoreCmsGoodsServices _goodsServices;
|
private readonly ICoreCmsGoodsServices _goodsServices;
|
||||||
private readonly ICoreCmsStoreServices _storeServices;
|
private readonly ICoreCmsStoreServices _storeServices;
|
||||||
private readonly ICoreCmsOrderDistributionModelServices _orderDistributionModelServices;
|
private readonly ICoreCmsOrderDistributionModelServices _orderDistributionModelServices;
|
||||||
|
private readonly IRedisOperationRepository _redisOperationRepository;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +61,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||||||
, ICoreCmsSettingServices settingServices
|
, ICoreCmsSettingServices settingServices
|
||||||
, ICoreCmsAreaServices areaServices
|
, ICoreCmsAreaServices areaServices
|
||||||
, ICoreCmsBillReshipServices reshipServices, ICoreCmsShipServices shipServices
|
, ICoreCmsBillReshipServices reshipServices, ICoreCmsShipServices shipServices
|
||||||
, ICoreCmsBillDeliveryServices billDeliveryServices, ICoreCmsLogisticsServices logisticsServices, ICoreCmsGoodsServices goodsServices, ICoreCmsStoreServices storeServices, ICoreCmsOrderDistributionModelServices orderDistributionModelServices)
|
, ICoreCmsBillDeliveryServices billDeliveryServices, ICoreCmsLogisticsServices logisticsServices, ICoreCmsGoodsServices goodsServices, ICoreCmsStoreServices storeServices, ICoreCmsOrderDistributionModelServices orderDistributionModelServices, IRedisOperationRepository redisOperationRepository)
|
||||||
{
|
{
|
||||||
_user = user;
|
_user = user;
|
||||||
_orderServices = orderServices;
|
_orderServices = orderServices;
|
||||||
@@ -73,6 +75,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||||||
_goodsServices = goodsServices;
|
_goodsServices = goodsServices;
|
||||||
_storeServices = storeServices;
|
_storeServices = storeServices;
|
||||||
_orderDistributionModelServices = orderDistributionModelServices;
|
_orderDistributionModelServices = orderDistributionModelServices;
|
||||||
|
_redisOperationRepository = redisOperationRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -155,53 +158,81 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||||||
{
|
{
|
||||||
var jm = new WebApiCallBack();
|
var jm = new WebApiCallBack();
|
||||||
|
|
||||||
var type = entity.receiptType;
|
var lockKey = "LOCK_CreateOrder:user_" + _user.ID;
|
||||||
if (type == (int)GlobalEnumVars.OrderReceiptType.Logistics || type == (int)GlobalEnumVars.OrderReceiptType.IntraCityService)
|
var redisUserLock = await _redisOperationRepository.LockTakeAsync(lockKey, _user.ID.ToString(), TimeSpan.FromSeconds(10));
|
||||||
|
if (redisUserLock)
|
||||||
{
|
{
|
||||||
//收货地址id
|
try
|
||||||
if (entity.ushipId == 0)
|
|
||||||
{
|
{
|
||||||
jm.data = 13001;
|
var type = entity.receiptType;
|
||||||
jm.msg = GlobalErrorCodeVars.Code13001;
|
switch (type)
|
||||||
|
{
|
||||||
|
case (int)GlobalEnumVars.OrderReceiptType.Logistics:
|
||||||
|
case (int)GlobalEnumVars.OrderReceiptType.IntraCityService:
|
||||||
|
{
|
||||||
|
//收货地址id
|
||||||
|
if (entity.ushipId == 0)
|
||||||
|
{
|
||||||
|
jm.data = 13001;
|
||||||
|
jm.msg = GlobalErrorCodeVars.Code13001;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (int)GlobalEnumVars.OrderReceiptType.SelfDelivery:
|
||||||
|
{
|
||||||
|
//提货门店
|
||||||
|
if (entity.storeId == 0)
|
||||||
|
{
|
||||||
|
jm.data = 13001;
|
||||||
|
jm.msg = GlobalErrorCodeVars.Code13001;
|
||||||
|
}
|
||||||
|
|
||||||
|
//提货人姓名 提货人电话
|
||||||
|
if (string.IsNullOrEmpty(entity.ladingName))
|
||||||
|
{
|
||||||
|
jm.data = 13001;
|
||||||
|
jm.msg = "请输入姓名";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(entity.ladingMobile))
|
||||||
|
{
|
||||||
|
jm.data = 13001;
|
||||||
|
jm.msg = "请输入电话";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
jm.data = 13001;
|
||||||
|
jm.msg = "未查询到配送方式";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(entity.cartIds))
|
||||||
|
{
|
||||||
|
jm.data = 10000;
|
||||||
|
jm.msg = GlobalErrorCodeVars.Code10000;
|
||||||
|
}
|
||||||
|
|
||||||
|
jm = await _orderServices.ToAdd(_user.ID, entity.orderType, entity.cartIds, entity.receiptType,
|
||||||
|
entity.ushipId, entity.storeId, entity.ladingName, entity.ladingMobile, entity.memo,
|
||||||
|
entity.point, entity.couponCode, entity.source, entity.scene, entity.taxType, entity.taxName,
|
||||||
|
entity.taxCode, entity.objectId, entity.teamId, entity.requireOrder, entity.requiredFundType,
|
||||||
|
entity.traceId);
|
||||||
}
|
}
|
||||||
}
|
catch (Exception e)
|
||||||
else if (type == (int)GlobalEnumVars.OrderReceiptType.SelfDelivery)
|
|
||||||
{
|
|
||||||
//提货门店
|
|
||||||
if (entity.storeId == 0)
|
|
||||||
{
|
{
|
||||||
jm.data = 13001;
|
jm.msg = "数据处理异常";
|
||||||
jm.msg = GlobalErrorCodeVars.Code13001;
|
jm.otherData = e;
|
||||||
}
|
}
|
||||||
//提货人姓名 提货人电话
|
finally
|
||||||
if (string.IsNullOrEmpty(entity.ladingName))
|
|
||||||
{
|
{
|
||||||
jm.data = 13001;
|
await _redisOperationRepository.LockReleaseAsync(lockKey, _user.ID.ToString());
|
||||||
jm.msg = "请输入姓名";
|
|
||||||
}
|
|
||||||
if (string.IsNullOrEmpty(entity.ladingMobile))
|
|
||||||
{
|
|
||||||
jm.data = 13001;
|
|
||||||
jm.msg = "请输入电话";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jm.data = 13001;
|
jm.msg = "当前请求太频繁_请稍后再试";
|
||||||
jm.msg = "未查询到配送方式";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(entity.cartIds))
|
|
||||||
{
|
|
||||||
jm.data = 10000;
|
|
||||||
jm.msg = GlobalErrorCodeVars.Code10000;
|
|
||||||
}
|
|
||||||
jm = await _orderServices.ToAdd(_user.ID, entity.orderType, entity.cartIds, entity.receiptType,
|
|
||||||
entity.ushipId, entity.storeId, entity.ladingName, entity.ladingMobile, entity.memo,
|
|
||||||
entity.point, entity.couponCode, entity.source, entity.scene, entity.taxType, entity.taxName,
|
|
||||||
entity.taxCode, entity.objectId, entity.teamId, entity.requireOrder, entity.requiredFundType, entity.traceId);
|
|
||||||
//jm.otherData = entity;
|
|
||||||
|
|
||||||
return jm;
|
return jm;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -14,16 +14,16 @@
|
|||||||
"PassWord": "CoreShopProfessional"
|
"PassWord": "CoreShopProfessional"
|
||||||
},
|
},
|
||||||
"AppConfig": {
|
"AppConfig": {
|
||||||
"AppUrl": "https://admin.pro.coreshop.cn/", //后端管理地址
|
"AppUrl": "https://admin.test.pro.coreshop.cn/", //后端管理地址
|
||||||
"AppInterFaceUrl": "https://api.pro.coreshop.cn/", //接口请求地址
|
"AppInterFaceUrl": "https://api.test.pro.coreshop.cn/", //接口请求地址
|
||||||
"AppVersion": "CoreShopProfessional v0.5.5"
|
"AppVersion": "CoreShopProfessional v0.6.0"
|
||||||
},
|
},
|
||||||
//redis为必须启动项,请保持redis为正常可用
|
//redis为必须启动项,请保持redis为正常可用
|
||||||
"RedisConfig": {
|
"RedisConfig": {
|
||||||
"UseCache": true, //启用redis作为内存选择
|
"UseCache": true, //启用redis作为内存选择
|
||||||
"UseTimedTask": true, //启用redis作为定时任务
|
"UseTimedTask": true, //启用redis作为定时任务
|
||||||
// 如果采用容器化部署Service 要写成redis的服务名,否则写地址
|
// 如果采用容器化部署Service 要写成redis的服务名,否则写地址
|
||||||
"ConnectionString": "127.0.0.1:6379,password=CoreShop,connectTimeout=3000,connectRetry=1,syncTimeout=10000,DefaultDatabase=9,abortConnect=false" //redis数据库连接字符串
|
"ConnectionString": "127.0.0.1:6379,password=coreshop,connectTimeout=30000,responseTimeout=30000,abortConnect=false,connectRetry=1,syncTimeout=10000,DefaultDatabase=9" //redis数据库连接字符串
|
||||||
},
|
},
|
||||||
//jwt授权认证的一些设置
|
//jwt授权认证的一些设置
|
||||||
"JwtConfig": {
|
"JwtConfig": {
|
||||||
@@ -220,11 +220,11 @@
|
|||||||
},
|
},
|
||||||
"PayCallBack": {
|
"PayCallBack": {
|
||||||
//微信支付回调
|
//微信支付回调
|
||||||
"WeChatPayUrl": "https://api.pro.coreshop.cn/Notify/WeChatPay/Unifiedorder",
|
"WeChatPayUrl": "https://api.test.pro.coreshop.cn/Notify/WeChatPay/Unifiedorder",
|
||||||
//微信退款回调
|
//微信退款回调
|
||||||
"WeChatRefundUrl": "https://api.pro.coreshop.cn/Notify/WeChatPay/Refund",
|
"WeChatRefundUrl": "https://api.test.pro.coreshop.cn/Notify/WeChatPay/Refund",
|
||||||
//支付宝支付回调
|
//支付宝支付回调
|
||||||
"AlipayUrl": "https://api.pro.coreshop.cn/Notify/AliPay/Unifiedorder",
|
"AlipayUrl": "https://api.test.pro.coreshop.cn/Notify/AliPay/Unifiedorder",
|
||||||
//支付宝退款回调
|
//支付宝退款回调
|
||||||
"AlipayRefundUrl": ""
|
"AlipayRefundUrl": ""
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user