public static async Task<bool> SetOrUpdateTimestampToNow(string uuid, string sessionid) { MessageCenterSessionRedis o = new MessageCenterSessionRedis(); o.UserUUID = uuid; o.SessionId = sessionid; o.TimeStamp = BK.CommonLib.Util.CommonHelper.GetUnixTimeNow(); return await _redis.SaveObjectAsync(o); }
/// <summary> /// 清空一个uuid,某个sessionid的聊天未读记录。 /// </summary> /// <param name="uuid"></param> /// <param name="sessionId"></param> /// <returns></returns> public static async Task<bool> CleanUnreadScore(string uuid,string sessionId) { MessageCenterSessionRedis o = new MessageCenterSessionRedis(); o.UserUUID = uuid; o.SessionId = sessionId; var db = _redis.GetDb<MessageCenterSessionRedis>(); string zsetName = _redis.GetKeyName<UnReadMessageCountZsetAttribute>(o); return await db.SortedSetAddAsync(zsetName, sessionId, 0); }
/// <summary> /// 判断一个用户是否有未读消息 /// </summary> /// <param name="uuid"></param> /// <returns></returns> public static async Task<bool> IsGetUnredScore(string uuid) { MessageCenterSessionRedis o = new MessageCenterSessionRedis(); o.UserUUID = uuid; string zsetName = _redis.GetKeyName<UnReadMessageCountZsetAttribute>(o); var pair = await _redis.GetRangeByRankWithScoreAsync<MessageCenterSessionRedis>(zsetName, from: 0, to: 0); if (pair == null || pair.Length==0) return false; return pair[0].Value > 0; }
/// <summary> /// 获取一个uuid某个聊天session的未读消息数量。 /// </summary> /// <param name="uuid"></param> /// <param name="sessionId"></param> /// <returns></returns> public static async Task<double> GetUnreadScore(string uuid, string sessionId) { MessageCenterSessionRedis o = new MessageCenterSessionRedis(); o.UserUUID = uuid;o.SessionId = sessionId; var db = _redis.GetDb<MessageCenterSessionRedis>(); string zsetName = _redis.GetKeyName<UnReadMessageCountZsetAttribute>(o); double? value = await db.SortedSetScoreAsync(zsetName, sessionId); if (value.HasValue) return value.Value; return 0; }
/// <summary> /// 按照时间先后顺序获取一个用户的聊天session /// </summary> /// <param name="uuid"></param> /// <param name="sessionId"></param> /// <param name="orderWay"></param> /// <param name="from"></param> /// <param name="to"></param> /// <returns>返回UUid的最近的会话session列表。</returns> public static async Task<KeyValuePair<string, double>[]> GetSessionsTimeStampByUuid(string uuid, Order orderWay = Order.Descending, long from = 0, long to = -1) { MessageCenterSessionRedis o = new MessageCenterSessionRedis(); o.UserUUID = uuid; string zsetName = _redis.GetKeyName<TimeStampZsetAttribute>(o); return await _redis.GetRangeByRankWithScoreAsync<MessageCenterSessionRedis>(zsetName, orderWay, from, to); }