/// <summary> /// 删除文件夹 /// </summary> public void Delete() { var db = RedisConnectionFactory.GetDatabase(); foreach (var endpoint in RedisConnectionFactory.GetEndPoints()) { var server = RedisConnectionFactory.GetServer(endpoint); foreach (var key in server.Keys()) { if (key.ToString().StartsWith(RedisFileEntry.FileKeyPrefix + FullPath + "/")) { db.KeyDelete(key); } } } }
/// <summary> /// 删除所有缓存值 /// </summary> public void Clear() { var db = RedisConnectionFactory.GetDatabase(); foreach (var endpoint in RedisConnectionFactory.GetEndPoints()) { var server = RedisConnectionFactory.GetServer(endpoint); foreach (var key in server.Keys()) { if (key.ToString().StartsWith(UniquePrefix)) { db.KeyDelete(key); } } } FallbackCache.Clear(); }
/// <summary> /// 获取缓存对象数量 /// </summary> public int Count() { int count = 0; foreach (var endpoint in RedisConnectionFactory.GetEndPoints()) { var server = RedisConnectionFactory.GetServer(endpoint); foreach (var key in server.Keys()) { if (key.ToString().StartsWith(UniquePrefix)) { count += 1; } } } count += FallbackCache.Count(); return(count); }
/// <summary> /// 枚举文件 /// </summary> public IEnumerable <IFileEntry> EnumerateFiles() { var db = RedisConnectionFactory.GetDatabase(); foreach (var endpoint in RedisConnectionFactory.GetEndPoints()) { var server = RedisConnectionFactory.GetServer(endpoint); foreach (var key in server.Keys()) { var keyStr = key.ToString(); if (keyStr.StartsWith(RedisFileEntry.FileKeyPrefix + FullPath + "/")) { var path = keyStr.Substring(RedisFileEntry.FileKeyPrefix.Length); var childPathParts = path.Substring(FullPath.Length + 1).Split('/'); if (childPathParts.Length == 1) { yield return(new RedisFileEntry(RedisConnectionFactory, path, false)); } } } } }