zoukankan      html  css  js  c++  java
  • Redis封装之Set

    RedisSetService:

        /// <summary>
        /// Set:用哈希表来保持字符串的唯一性,没有先后顺序,存储一些集合性的数据
        /// 1.共同好友、二度好友
        /// 2.利用唯一性,可以统计访问网站的所有独立 IP
        /// </summary>
        public class RedisSetService : RedisBase
        {
            #region 添加
            /// <summary>
            /// key集合中添加value值
            /// </summary>
            public void Add(string key, string value)
            {
                RedisBase.iClient.AddItemToSet(key, value);
            }
            /// <summary>
            /// key集合中添加list集合
            /// </summary>
            public void Add(string key, List<string> list)
            {
                RedisBase.iClient.AddRangeToSet(key, list);
            }
            #endregion
    
            #region 获取
            /// <summary>
            /// 随机获取key集合中的一个值
            /// </summary>
            public string GetRandomItemFromSet(string key)
            {
                return RedisBase.iClient.GetRandomItemFromSet(key);
            }
            /// <summary>
            /// 获取key集合值的数量
            /// </summary>
            public long GetCount(string key)
            {
                return RedisBase.iClient.GetSetCount(key);
            }
            /// <summary>
            /// 获取所有key集合的值
            /// </summary>
            public HashSet<string> GetAllItemsFromSet(string key)
            {
                return RedisBase.iClient.GetAllItemsFromSet(key);
            }
            #endregion
    
            #region 删除
            /// <summary>
            /// 随机删除key集合中的一个值
            /// </summary>
            public string RandomRemoveItemFromSet(string key)
            {
                return RedisBase.iClient.PopItemFromSet(key);
            }
            /// <summary>
            /// 删除key集合中的value
            /// </summary>
            public void RemoveItemFromSet(string key, string value)
            {
                RedisBase.iClient.RemoveItemFromSet(key, value);
            }
            #endregion
    
            #region 其它
            /// <summary>
            /// 从fromkey集合中移除值为value的值,并把value添加到tokey集合中
            /// </summary>
            public void MoveBetweenSets(string fromkey, string tokey, string value)
            {
                RedisBase.iClient.MoveBetweenSets(fromkey, tokey, value);
            }
            /// <summary>
            /// 返回keys多个集合中的并集,返还hashset
            /// </summary>
            public HashSet<string> GetUnionFromSets(params string[] keys)
            {
                return RedisBase.iClient.GetUnionFromSets(keys);
            }
            /// <summary>
            /// 返回keys多个集合中的交集,返还hashset
            /// </summary>
            public HashSet<string> GetIntersectFromSets(params string[] keys)
            {
                return RedisBase.iClient.GetIntersectFromSets(keys);
            }
            /// <summary>
            /// 返回keys多个集合中的差集,返还hashset
            /// </summary>
            /// <param name="fromKey">原集合</param>
            /// <param name="keys">其他集合</param>
            /// <returns>出现在原集合,但不包含在其他集合</returns>
            public HashSet<string> GetDifferencesFromSet(string fromKey, params string[] keys)
            {
                return RedisBase.iClient.GetDifferencesFromSet(fromKey,keys);
            }
            /// <summary>
            /// keys多个集合中的并集,放入newkey集合中
            /// </summary>
            public void StoreUnionFromSets(string newkey, string[] keys)
            {
                RedisBase.iClient.StoreUnionFromSets(newkey, keys);
            }
            /// <summary>
            /// 把fromkey集合中的数据与keys集合中的数据对比,fromkey集合中不存在keys集合中,则把这些不存在的数据放入newkey集合中
            /// </summary>
            public void StoreDifferencesFromSet(string newkey, string fromkey, string[] keys)
            {
                RedisBase.iClient.StoreDifferencesFromSet(newkey, fromkey, keys);
            }
            #endregion
        }
    

      

  • 相关阅读:
    WPF 中 UserControl作为另一个Process宿主到Window里, ErrorTemplate的默认红框没有出现
    WPF error: does not contain a static 'Main' method suitable for an entry point
    C#编译问题'System.Collections.Generic.IEnumerable' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument
    C# 序列化反序列化XML的帮助类
    利用反射拿到并递归C#类中的各个字段名字及类型
    XmlSerialize error: There was an error generating the XML document.
    No overload for 'OnStartup' matches delegate 'System.Windows.StartupEventHandler'
    Linq 支持动态字查询集合, 也就是说根据传入的值进行查询。
    JsonCpp的使用
    win32 UNICODE 支持
  • 原文地址:https://www.cnblogs.com/marshhu/p/6765110.html
Copyright © 2011-2022 走看看