.NET中keyPrefix的属性定义

属性值

String
一个 String,它包含隐式资源表达式的前缀。

KeyPrefix属性将可以分配给控件的属性集合结合在一起。 KeyPrefix属性指的是表达式中的冒号 (: ) 的值(如果存在),在第一个句点 ( 之前。 ) 

 /// <summary>
    /// 点赞业务逻辑类
    /// </summary>
    public class LikeManager : ILikeManager
    {
        private const string keyPrefix = "VideoLike";

        /// <summary>
        /// 点赞计数
        /// </summary>
        /// <param name="videoId">视频Id</param>
        /// <returns></returns>
        public long Count(string videoId)
        {
            string key = $"{keyPrefix}_{videoId}";
            return RedisHelper.SetLength(key);
        }

        /// <summary>
        /// 是否已点赞
        /// </summary>
        /// <param name="videoId">视频Id</param>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        public bool IsLike(string videoId, int userId)
        {
            string key = $"{keyPrefix}_{videoId}";
            return RedisHelper.SetContains(key, userId);
        }

        /// <summary>
        /// 添加点赞
        /// </summary>
        /// <param name="videoId">视频Id</param>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        public bool AddLike(string videoId, int userId)
        {
            string key = $"{keyPrefix}_{videoId}";
            return RedisHelper.SetAdd(key, userId);
        }

        /// <summary>
        /// 移除点赞
        /// </summary>
        /// <param name="videoId">视频Id</param>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        public bool RemoveLike(string videoId, int userId)
        {
            string key = $"{keyPrefix}_{videoId}";
            return RedisHelper.SetRemove(key, userId);
        }
    }

 

posted @ 2021-12-14 21:10  顾屿南歌  阅读(53)  评论(0编辑  收藏  举报