public void UnfollowGroup(string groupId, string followerId) { var entryKey = GetEntryKey(GroupCachePrefix, groupId); var db = StackExchangeRedisConnectionProvider.GetDataBase(); db.SetRemove(entryKey, followerId); }
public void IncrementCommentLikeCount(long commentId) { var entryKey = GetEntryKey(commentLikeCounterPrefix, commentId.ToString()); var db = StackExchangeRedisConnectionProvider.GetDataBase(); db.StringIncrement(entryKey); }
public IEnumerable <string> GetGroupFollowers(string groupId) { var entryKey = GetEntryKey(GroupCachePrefix, groupId); var db = StackExchangeRedisConnectionProvider.GetDataBase(); return(db.SetMembers(entryKey).Select(p => p.ToString())); }
public void RemovePost(string postId) { var entryKey = GetEntryKey(CacheEntryPrefix, postId); var db = StackExchangeRedisConnectionProvider.GetDataBase(); db.KeyDelete(entryKey); }
public void ClearGroupWall(string groupId) { var key = GetEntryKey(FeedPrefix, groupId); var db = StackExchangeRedisConnectionProvider.GetDataBase(); db.KeyDelete(key); }
public void FollowUser(string userId, string followerId) { var entryKey = GetEntryKey(UserCachePrefix, userId); var db = StackExchangeRedisConnectionProvider.GetDataBase(); db.SetAdd(entryKey, followerId); }
public void IncrementPostLikeCount(string postId) { var entryKey = GetEntryKey(postLikeCounterPrefix, postId); var db = StackExchangeRedisConnectionProvider.GetDataBase(); db.StringIncrement(entryKey); }
void ICommentCountCacheRepository.Increment(string postId) { var entryKey = GetEntryKey(RedisNameConstants.CommentCounterNamePrefix, postId); var db = StackExchangeRedisConnectionProvider.GetDataBase(); db.StringIncrement(entryKey); }
public void Remove(string postId) { var entryKey = GetEntryKey(RedisNameConstants.CommentCounterNamePrefix, postId); var db = StackExchangeRedisConnectionProvider.GetDataBase(); db.KeyDelete(entryKey); }
public WallPostCacheModel GetPost(string postId) { var entryKey = GetEntryKey(CacheEntryPrefix, postId); var db = StackExchangeRedisConnectionProvider.GetDataBase(); var item = db.StringGet(entryKey); return(!string.IsNullOrWhiteSpace(item) ? JsonConvert.DeserializeObject <WallPostCacheModel>(item) : null); }
public void SavePost(WallPostCacheModel model) { var entryKey = GetEntryKey(CacheEntryPrefix, model.Id); var item = JsonConvert.SerializeObject(model); var db = StackExchangeRedisConnectionProvider.GetDataBase(); db.StringSet(entryKey, item); }
public int GetCommentCount(string postId) { var entryKey = GetEntryKey(RedisNameConstants.CommentCounterNamePrefix, postId); var db = StackExchangeRedisConnectionProvider.GetDataBase(); var value = db.StringGet(entryKey); return(!string.IsNullOrWhiteSpace(value) ? Convert.ToInt32(value) : 0); }
public int GetCommentLikeCount(long commentId) { var entryKey = GetEntryKey(commentLikeCounterPrefix, commentId.ToString()); var db = StackExchangeRedisConnectionProvider.GetDataBase(); var value = db.StringGet(entryKey); return(!string.IsNullOrWhiteSpace(value) ? Convert.ToInt32(value) : 0); }
public void RemovePosts(IEnumerable <string> postIds) { var keyList = new List <RedisKey>(); foreach (var postId in postIds) { keyList.Add(GetEntryKey(CacheEntryPrefix, postId)); } var db = StackExchangeRedisConnectionProvider.GetDataBase(); db.KeyDelete(keyList.ToArray()); }
public IEnumerable <WallPostCacheModel> GetItems(IEnumerable <string> postIds) { var result = new List <WallPostCacheModel>(); var entryKeys = postIds.Select(t => GetEntryKey(CacheEntryPrefix, t)).Select(p => (RedisKey)p).ToArray(); var db = StackExchangeRedisConnectionProvider.GetDataBase(); var results = db.StringGet(entryKeys); foreach (var resultItem in results) { if (!string.IsNullOrWhiteSpace(resultItem)) { result.Add(JsonConvert.DeserializeObject <WallPostCacheModel>(resultItem)); } } return(result); }
public IEnumerable <GroupWallResponseModel> GetGroupWall(string groupId) { var result = new List <GroupWallResponseModel>(); var key = GetEntryKey(FeedPrefix, groupId); var db = StackExchangeRedisConnectionProvider.GetDataBase(); var allPostIds = db.SetMembers(key).ToList(); if (allPostIds != null && allPostIds.Count > 0) { var postKeys = allPostIds.Select(p => (RedisKey)GetEntryKey(RedisNameConstants.WallPostRepoPrefix, p)).ToArray(); var likeKeys = allPostIds.Select(p => (RedisKey)GetEntryKey(RedisNameConstants.PostLikeCounterNamePrefix, p)).ToArray(); var comment = allPostIds.Select(p => (RedisKey)GetEntryKey(RedisNameConstants.CommentCounterNamePrefix, p)).ToArray(); //foreach (var postId in allPostIds) //{ //var transaction = db.CreateTransaction(); //var posts = transaction.StringGetAsync(postKeys); var posts = db.StringGet(postKeys); foreach (var post in posts) { var currentPost = JsonConvert.DeserializeObject <WallPostCacheModel>(post); var model = new GroupWallResponseModel { Body = currentPost.Body, CreatedDate = currentPost.CreatedDate, Id = currentPost.Id, ModifiedDate = currentPost.ModifiedDate, PostedBy = currentPost.PostedBy, PostType = currentPost.PostType, WallOwner = new WallModel { OwnerId = currentPost.TargetWall.Id, WallOwnerType = (WallType)currentPost.TargetWall.WallOwnerTypeId }, }; var currentCommentCountEntry = GetEntryKey(RedisNameConstants.CommentCounterNamePrefix, currentPost.Id); var totalCommentCountEntry = db.StringGet(currentCommentCountEntry); model.CommentCount = !string.IsNullOrWhiteSpace(totalCommentCountEntry) ? Convert.ToInt32(totalCommentCountEntry) : 0; var totalLikeCountEntryKey = GetEntryKey(RedisNameConstants.PostLikeCounterNamePrefix, currentPost.Id); var value = db.StringGet(totalLikeCountEntryKey); model.LikeCount = !string.IsNullOrWhiteSpace(value) ? Convert.ToInt32(value) : 0; result.Add(model); } //JsonConvert.DeserializeObject<List<WallPostCacheModel>>(); // var comments = transaction.StringGetAsync(comment); // transaction.Execute(); // var entryKey = GetEntryKey(RedisNameConstants.WallPostRepoPrefix, postId); // var currentPostValue = db.StringGet(entryKey); //// var currentPost = !string.IsNullOrWhiteSpace(currentPostValue) ? JsonConvert.DeserializeObject<WallPostCacheModel>(currentPostValue) : null; // if (!string.IsNullOrWhiteSpace(currentPostValue)) // { // //var currentCommentCountEntry = GetEntryKey(RedisNameConstants.CommentCounterNamePrefix, postId); // //var totalCommentCountEntry = db.StringGet(currentCommentCountEntry); // //var totalCommentCount = !string.IsNullOrWhiteSpace(totalCommentCountEntry) ? Convert.ToInt32(totalCommentCountEntry) : 0; // //var totalLikeCountEntryKey = GetEntryKey(RedisNameConstants.PostLikeCounterNamePrefix, postId); // //var value = db.StringGet(entryKey); // //var totalLikeCount = !string.IsNullOrWhiteSpace(value) ? Convert.ToInt32(value) : 0; // var model = new GroupWallResponseModel // { // //Body = currentPost.Body, // //CreatedDate = currentPost.CreatedDate, // Id = "123"//, // //ModifiedDate = currentPost.ModifiedDate, // //PostedBy = currentPost.PostedBy, // //PostType = currentPost.PostType, // //WallOwner = new WallModel { OwnerId = currentPost.TargetWall.Id, WallOwnerType = (WallType)currentPost.TargetWall.WallOwnerTypeId }, // //LikeCount = totalLikeCount, // //CommentCount = totalCommentCount // }; // result.Add(model); //} //} } return(result); }
public IEnumerable <NewsfeedResponseModel> GetUserFeed(string userId, int skip, int take) { var userFeedKey = GetEntryKey(FeedPrefix, userId); List <NewsfeedResponseModel> responseItems = new List <NewsfeedResponseModel>(); var startIndex = skip; var counter = 0; var db = StackExchangeRedisConnectionProvider.GetDataBase(); var allPostIds = db.SetMembers(userFeedKey).ToList(); if (allPostIds != null && allPostIds.Count > 0) { IEnumerable <RedisValue> postIds; if (allPostIds.Count > take) { postIds = allPostIds.Skip(skip).Take(take); } else { postIds = allPostIds.Take(take); } foreach (var postId in postIds) { //Read post from cache var currentPost = wallPostRepo.GetPost(postId); if (currentPost != null) { var userActionsOnPostKey = GetEntryKey(FeedPrefix, string.Concat(userId, ":", postId)); //10000 is just a random rank assumed to be the max events on a post var userActionsOnPost = db.SortedSetRangeByScoreWithScores(userActionsOnPostKey, 0, 10000); if (userActionsOnPost != null && userActionsOnPost.Length > 0) { var mappedActions = new List <NewsfeedAction>(); foreach (var action in userActionsOnPost) { var values = action.Element.ToString().Split(':'); mappedActions.Add(new NewsfeedAction { Action = (NewsfeedActionType)Convert.ToInt16(values[1]), By = values[0] }); } var totalCommentCount = commentCountRepo.GetCommentCount(currentPost.Id); var totalLikeCount = entryLikeRepo.GetPostLikeCount(currentPost.Id); var model = new NewsfeedResponseModel { Body = currentPost.Body, CreatedDate = currentPost.CreatedDate, Id = currentPost.Id, ModifiedDate = currentPost.ModifiedDate, PostedBy = currentPost.PostedBy, PostType = currentPost.PostType, WallOwner = new WallModel { OwnerId = currentPost.TargetWall.Id, WallOwnerType = (WallType)currentPost.TargetWall.WallOwnerTypeId }, FeedDescription = mappedActions, LikeCount = totalLikeCount, CommentCount = totalCommentCount }; responseItems.Add(model); counter++; if (counter == take) { break; } } else { db.SetRemove(userFeedKey, postId); db.KeyDelete(userActionsOnPostKey); } } else { db.SetRemove(userFeedKey, postId); } } } return(responseItems); }