/// <summary>
        /// 是否存在key
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool Exists(string key)
        {
            try
            {
                if (AllKeys.Contains(key))
                {
                    return(true);
                }
                if (pool != null)
                {
                    using var r = pool.GetClient();
                    if (r != null)
                    {
                        r.SendTimeout = 1000;
                        return(r.ContainsKey(key));
                    }
                }
            }
            catch
            {
                throw new Exception(string.Format("{0}:{1}发生异常!{2}", "cache", "是否存在", key));
            }

            return(false);
        }
Exemple #2
0
 public void AddMissing(string key, string value)
 {
     if (AllKeys.Contains(key))
     {
         return;
     }
     Add(key, value);
 }
Exemple #3
0
        public async Task SaveAllAsync()
        {
            var db     = _services.CreateScope().ServiceProvider.GetRequiredService <IKeyValueDbContext>();
            var fromDb = db.KeyValues.ToList();
            var adding = Items.Where(x => !fromDb.Any(d => x.Key == d.Key)).ToList();

            fromDb.RemoveAll(x => !AllKeys.Contains(x.Key));
            fromDb.ForEach(x => x.Value = Get(x.Key));
            db.KeyValues.AddRange(adding);

            await db.Normalize().SaveChangesAsync();
        }
Exemple #4
0
 public string this[string name]
 {
     get
     {
         if (AllKeys.Contains(name))
         {
             var str = config.GetSection(sectionName)[name];//第一种方法
             return(str);
         }
         return("");
     }
 }
        /// <summary>
        /// Get all of the data in the requested column of the table.
        /// if an invalid header is given, throws an ArgumentOutOfRangeException.
        /// </summary>
        /// <param name="header">Column Header from this table.</param>
        /// <returns></returns>
        public List <String> GetColumn(String header)
        {
            if (!AllKeys.Contains(header))
            {
                throw new ArgumentOutOfRangeException("Invalid Header Name");
            }

            List <String> column = new List <string>();

            foreach (Dictionary <String, String> row in Data)
            {
                if (!row.ContainsKey(header))
                {
                    column.Add("");
                }
                else
                {
                    column.Add(row[header]);
                }
            }

            return(column);
        }
Exemple #6
0
 public ConnectionStringSettings this[string name]
 {
     get
     {
         if (AllKeys.Contains(name))
         {
             ConnectionStringSettings rev = new ConnectionStringSettings();
             var item = config.GetSection(sectionName).GetSection(name);//第一种方法
             foreach (var kv in item.AsEnumerable())
             {
                 if (kv.Key == $"ConnectionStrings:{name}:ConnectionString")
                 {
                     rev.ConnectionString = kv.Value;
                 }
                 if (kv.Key == $"ConnectionStrings:{name}:ProviderName")
                 {
                     rev.ProviderName = kv.Value;
                 }
             }
             return(rev);
         }
         return(null);
     }
 }
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool Delete(string key)
 {
     try
     {
         if (AllKeys.Contains(key))
         {
             Remove(key);
         }
         if (pool != null)
         {
             using var r = pool.GetClient();
             if (r != null)
             {
                 r.SendTimeout = 1000;
                 r.Remove(key);
             }
         }
     }
     catch
     {
         throw new Exception(string.Format("{0}:{1}发生异常!{2}", "cache", "删除", key));
     }
     return(true);
 }