public async Task <UserDto> get_userbyuserid(Guid userid)
        {
            var cachekey    = $"user_{userid.ToString()}";
            var userdto_str = await _redis.StringGetAsync(cachekey);

            if (String.IsNullOrEmpty(userdto_str))
            {
                var usermodel = await _repository.get_userinfo(userid);

                if (usermodel != null)
                {
                    var userdto = new UserDto()
                    {
                        Id = usermodel.Id, user_status = usermodel.user_status, user_name = usermodel.user_name, user_phone = usermodel.user_phone
                    };
                    await _redis.StringSetAsync(cachekey, Newtonsoft.Json.JsonConvert.SerializeObject(userdto));

                    return(userdto);
                }
            }
            else
            {
                return(Newtonsoft.Json.JsonConvert.DeserializeObject <UserDto>(userdto_str));
            }
            return(null);
        }
        public async Task <string> GetAsync([FromServices] IRedisHelper redis)
        {
            const string key = "msg";
            await redis.StringSetAsync(key, "hello world");

            return(await redis.StringGetAsync <string>(key));
        }
Esempio n. 3
0
        public async Task StringTestAsync()
        {
            const string key   = "name";
            const string value = "colin";

            Assert.True(await _redis.StringSetAsync(key, value));
            Assert.Equal(value, await _redis.StringGetAsync <string>(key));
            Assert.Null(await _redis.StringGetAsync <string>("not_exist"));

            const string objKey = "person";
            var          people = new People("colin", 18);

            Assert.True(await _redis.StringSetAsync("person", people));
            Assert.Equal(people, await _redis.StringGetAsync <People>(objKey), new PeopleComparer());

            Assert.Equal(2, await _redis.KeyDeleteAsync(new[] { key, objKey }));
        }