Exemplo n.º 1
0
        public async Task GetOrSetAsync()
        {
            string key    = "GetOrSetAsync";
            var    value  = Guid.NewGuid().ToString();
            var    result = await _redisDatabase.GetOrSetAsync <string>(key, async() => { return(await Task.FromResult(value)); });

            Assert.AreEqual(value, result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据key查询redis,不存在则查询数据库并将结果插入Redis
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ResponseResult <XXXAo> > GetOrCreateAsync(uint id)
        {
            var result = await _redisManager.GetOrSetAsync <XXXAo>($"RedisOption:Id{id}", async() =>
            {
                var @result = await _dataBaseOptionService.FindAsync(id);
                return(@result.Result);
            });

            return(new ResponseResult <XXXAo>
            {
                Result = result,
            });
        }