/// <summary> /// Delete question by performing compensating actions to StoreQuestion() to keep the datastore in a consistent state /// </summary> /// <param name="questionId"></param> public void DeleteQuestion(long questionId) { using (var redis = RedisManager.GetClient()) { var redisQuestions = redis.As <Question>(); var question = redisQuestions.GetById(questionId); if (question == null) { return; } //decrement score in tags list question.Tags.ForEach(tag => redis.IncrementItemInSortedSet(TagIndex.All, tag, -1)); //remove all related answers redisQuestions.DeleteRelatedEntities <Answer>(questionId); //remove this question from user index redis.RemoveItemFromSet(UserQuestionIndex.Questions(question.UserId), questionId.ToString()); //remove tag => questions index for each tag question.Tags.ForEach(tag => redis.RemoveItemFromSet(TagIndex.Questions(tag), questionId.ToString())); redisQuestions.DeleteById(questionId); } }
public void StoreQuestion(Question question) { using (var redis = RedisManager.GetClient()) { var redisQuestions = redis.As <Question>(); if (question.Tags == null) { question.Tags = new List <string>(); } if (question.Id == default(long)) { question.Id = redisQuestions.GetNextSequence(); question.CreatedDate = DateTime.UtcNow; //Increment the popularity for each new question tag question.Tags.ForEach(tag => redis.IncrementItemInSortedSet(TagIndex.All, tag, 1)); } redisQuestions.Store(question); redisQuestions.AddToRecentsList(question); redis.AddItemToSet(UserQuestionIndex.Questions(question.UserId), question.Id.ToString()); //Populate tag => questions index for each tag question.Tags.ForEach(tag => redis.AddItemToSet(TagIndex.Questions(tag), question.Id.ToString())); } }
public List <QuestionResult> GetQuestionsTaggedWith(string tagName) { using var redis = RedisManager.GetReadOnlyClient(); var questionIds = redis.GetAllItemsFromSet(TagIndex.Questions(tagName)); var questions = redis.As <Question>().GetByIds(questionIds); return(ToQuestionResults(questions)); }