redis在c中返回null#

am46iovg  于 2021-06-09  发布在  Redis
关注(0)|答案(0)|浏览(179)

我在一个后台任务中实现了redis,所以我在控制器中创建了以下两个私有方法:

private bool SaveCacheProgress(string key, string value)
{
    bool isSuccess = false;

    TimeSpan timeSpan = TimeSpan.FromHours(1);
    isSuccess = _cacheProvider.Set(key, value, timeSpan);

    return isSuccess;
}

private string GetCacheProgress(string key)
{
    return _cacheProvider.Get<string>(key);
}

我的 SaveCacheProgress 方法工作得很好,因为我在redis cli中看到了它,但是如果我尝试获取缓存中的项,它将返回null,并且我已经验证了密钥是正确的,并且它仍然在我的redis缓存中

[HttpPost]
[Route("UploadVerificationFileAsync/{connectionId}")]
[TrackActivity(section: "Upload", actionType: UserActivityActionType.Upload, actionDescription: "Upload Verification File")]
public async Task<IHttpActionResult> UploadVerificationFileAsync(Guid scorecardId, string connectionId)
{
    var username = this.GetUserFromDatabase().UserName;
    string cacheKey = scorecardId.ToString() + username;
    string check = GetCacheProgress(cacheKey);

    if (check == CacheConstants.progress[1])
    {
        throw new FileInProgressException("File Upload still in progress");
    }
    bool started = SaveCacheProgress(cacheKey, CacheConstants.progress[0]);

所以 bool started = SaveCacheProgress(cacheKey, CacheConstants.progress[0]); 很好用,但如果我试一下 GetCacheProgress 对于完全相同的键变量,它仍然返回null

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题