Beispiel #1
0
        public void Create(User user)
        {
            var db = _redisProvider.Database();

            user.Password = BCrypt.Net.BCrypt.HashPassword(user.Password);
            var userHash = RedisHelper.ToHashEntries(user);

            db.HashSet(UserKey(user.Id), userHash);
        }
Beispiel #2
0
        public Book Get(string id)
        {
            var db       = _redisProvider.Database();
            var bookHash = db.HashGetAll(BookKey(id));
            var book     = RedisHelper.ConvertFromRedis <Book>(bookHash);
            var authors  = db.SetMembers(BookAuthorKey(id));

            book.Authors = authors.Select(author => author.ToString()).ToArray();
            return(book);
        }
Beispiel #3
0
        public Cart Get(long id)
        {
            var db     = _redisProvider.Database();
            var result = db.JsonGet(CartKey(id));

            if (result.IsNull)
            {
                return(null);
            }
            var cart = JsonConvert.DeserializeObject <Cart>(result.ToString() ?? throw new InvalidOperationException());

            return(cart);
        }
        public async Task <Book> CreateBook(Book book)
        {
            var db = await _redisProvider.Database();

            var bookKey   = new RedisKey(book.GetType().Name + ":" + book.Id);
            var authorKey = new RedisKey(book.GetType().Name + ":" + book.Id + ":authors");
            await db.HashSetAsync(bookKey, RedisConverter.ToHashEntries(book));

            foreach (var author in book.Authors)
            {
                await db.SetAddAsync(authorKey, author);
            }

            return(await GetBook(book.Id));
        }