Beispiel #1
0
        public async Task <RetwisUser> GetUserAsync(string username, string password)
        {
            var db = _context.GetDatabase();

            var details = (await db.HashGetAllAsync(GetUserKey(username))).ToDictionary();

            if (!details.Any() || details["password"] != password)
            {
                return(null);
            }
            return(new RetwisUser(username, Guid.Parse(details["user_identifier"])));
        }
Beispiel #2
0
        public async Task <LatestRegisteredUser[]> GetLatestUsers()
        {
            var db    = _context.GetDatabase();
            var users = await db.SortedSetRangeByRankAsync("users_by_time", stop : 9, order : Order.Descending);

            return(users.Select(x => new LatestRegisteredUser(x)).ToArray());
        }
Beispiel #3
0
        public async Task UpdateStatusAsync(Guid userIdentifier, string status)
        {
            var db = _context.GetDatabase();

            // persist the post
            var postId = db.StringIncrement("next_post_id");

            db.HashSet("post:" + postId, new[]
            {
                new HashEntry("user_id", userIdentifier.ToString()),
                new HashEntry("time", DateTime.Now.Ticks),
                new HashEntry("status", status),
            });

            // push to follower's timelines
            var followers = await db.SortedSetRangeByScoreAsync("followers:" + userIdentifier);

            foreach (var follower in followers)
            {
                await db.ListLeftPushAsync("posts:" + follower, postId);
            }

            // push to my timeline
            await db.ListLeftPushAsync("posts:" + userIdentifier, postId);

            // push to the timeline and trim to last 1000
            await db.ListLeftPushAsync("timeline", postId);

            await db.ListTrimAsync("timeline", 0, 1000);
        }
        public async Task <LatestMessage[]> GetLatestMessages()
        {
            var db      = _context.GetDatabase();
            var postIds = await db.ListRangeAsync("timeline", 0, -1);

            var posts =
                await _latestMessageRepository.GetMessagesFor(db, postIds.Select(x => long.Parse(x)).ToArray());

            return(posts.ToArray());
        }
        public async Task <LatestMessage[]> GetLatestMessagesAsync(Guid userIdentifier)
        {
            var db      = _context.GetDatabase();
            var postIds = await db.ListRangeAsync("posts:" + userIdentifier, 0, -1);

            var posts =
                await _latestMessageRepository.GetMessagesFor(db, postIds.Select(x => long.Parse(x)).ToArray());

            return(posts.ToArray());
        }