我有以下班级女巫在论坛中存储消息
using System;
using System.Collections.Generic;
public partial class ForumMessage
{
public ForumMessage()
{
this.Votes = new HashSet<ForumMessageVote>();
OnCreated();
}
partial void OnCreated();
public long id { get; set; }
public int forumId { get; set; }
public Nullable<long> parentId { get; set; }
public int memberId { get; set; }
public int lastModifiedMemberId { get; set; }
public Nullable<long> lastReplyId { get; set; }
public string title { get; set; }
public string body { get; set; }
public string imagePath { get; set; }
public Nullable<bool> isSticky { get; set; }
public Nullable<bool> allowPosts { get; set; }
public Nullable<bool> allowImages { get; set; }
public Nullable<bool> allowYoutube { get; set; }
public Nullable<bool> allowBbCode { get; set; }
public Nullable<long> totalMessages { get; set; }
public Nullable<long> totalViews { get; set; }
public Nullable<long> totalDailyViews { get; set; }
public Nullable<int> totalVotes { get; set; }
public Nullable<long> totalScore { get; set; }
public bool published { get; set; }
public Nullable<System.DateTime> publishedDate { get; set; }
public Nullable<System.DateTime> lastModifiedDate { get; set; }
public Nullable<bool> isTemporary { get; set; }
public Nullable<System.DateTime> lastReplyDate { get; set; }
public Nullable<int> lastReplyMemberId { get; set; }
public Nullable<long> sortByLastReplyId { get; set; }
public Nullable<bool> containsImage { get; set; }
public Nullable<bool> containsVideo { get; set; }
public Nullable<bool> @private { get; set; }
public virtual Forum Forum { get; set; }
public virtual ICollection<ForumMessageVote> Votes { get; set; }
public virtual Member Member { get; set; }
}
目前,我正在使用 Booksleeve 缓存这些对象,方法是使用以下代码(简化版本)将它们与 Json 序列化存储在字符串键中(如果在 Redis 中):
using (var conn = conn.CreateTransaction())
{
return conn.Store<ForumMessage>(db, message.id, message);
}
在我的论坛应用程序视图中,我使用了上述大部分字段,因为我显示了属于论坛线程的上述消息的列表。
为了获取 ForumMessage 类的列表,我使用了mget命令。
当用户发布新消息或为消息投票时,我需要更新上述某些字段。当我更新时,我通过 redis get获取消息,更新所需的字段/字段(主要是一个或两个字段),然后我通过conn.store booksleeve 方法存储更新。
目前论坛高峰时段收到约12条消息/分钟和20票/分钟(总票数不是每条消息)
如果上述问题的更优解决方案是将消息存储在 redis 哈希中,我会徘徊,因为这样更新会更快。但是为了使用哈希,在 redis 上进行初始存储的代码会更复杂(慢),并且此代码将在 Web 服务器而不是 redis 服务器上运行。
您是否认为值得通过使用哈希来重新实现消息存储/检索过程,或者当消息插入率以 30 条消息/分钟增加时,比我现在使用的解决方案能够很好地扩展?
本质上,您能否就stackoverflow如何处理这种情况提供一些指导?