惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - Flymouse

Error CS0006 when invoking MSBuild from command line 一个Cookie引起的混乱 数据库错误:在执行批处理时出现错误。错误消息为: 目录名无效 使用网络目录映射虚拟目录出现 500.19 权限不足问题的一个解决办法 URL重写给 asp.net Ajax带来的问题 调整viewState的位置,有助于SEO C# Excel进程关闭 - Flymouse - 博客园 关于限制水晶报表的导出格式 2个Excel异常处理 Win7 x64 IIS7支持32位应用程序 在.net中与mysql数据库的时候碰到显示不了中文字符的情况实现! 完美解决IFRAME中COOKIE、SESSION丢失 关于Ucenter在IIS中有时出现“Access denied for agent changed”错误。 如何將 Access 的 Memo 型態欄位匯入到 SQL2005 的 nvarchar 型態欄位 .net wap强制输出WML - Flymouse - 博客园 使用Extjs的Form无法输入的问题 jQuery滚屏代码,还有一点地方封装不进去 - Flymouse - 博客园 ASP.NET 2.0 中动态添加 GridView 模板列的例子 关于使用 jquery Validate 使用出现的问题
NorthScale MemBase Server 1.6 的使用
Flymouse · 2010-09-11 · via 博客园 - Flymouse

前几天听到Dudu介绍NorthScale Memcached Server, 感觉很不错,从配置到监控都很方便,于是准备尝试一下。当时在我的Win7 64x安装比较顺利,没有碰到问题,但是安装在一台Win2008 32x的服务器上是总是无法启动,日志提示:

Erlang machine stopped instantly (distribution name conflict?). The service is not restarted, ignoring OnFail option.

从提示表面是服务获知准确的错误信息,经过多次测试发现,是在同一块网卡上绑定多个IP时就会发生这个错误,向NorthScale的开发人员反应问题并希望得到解决,他们给了个重新设置服务IP的方法,如下:

1. from "INSTALLDIR\Memcached Server\bin"
2. run "service_stop.bat"
3. run "service_unregister.bat"
4. run "service_register.bat ns_1@<PHYSICAL IP>"
5. run "service_start.bat"

但是我测试了几次,对多IP没有效果,仍然无法启动服务。

如果服务安装在单IP网卡,以前是正常启动的,在IP发生改变时可以用这个方法修改服务绑定的IP。

一直在等待他们的NorthScale MemBase Server 这个产品的和NorthScale Memcahced Server区别是,MemBase Server的数据会dump到地盘,可以做分布式数据库使用。

之前看姜敏的NorthScale Memcached Server尝试总结中熊哥提到无法使用stats cachedump命令,我看了一下,可能是NorthScale使用Memcached的二进制协议通讯,二进制协议比文本协议高效,但是不支持stats cachedump命令。

前天看到NorthScale MateBase Server 1.6 Beta3发布了,拿来安装测试,发现当初说在此版本要解决的网卡多IP问题还没有解决,期待正式版。

现在需要在生产环境中使用NorthScale,但是他不支持stats cachedump,无法获取缓存中的缓存项的key,只好想了一个折中的办法,通过一个缓存来保存目前缓存列表,在每次set时,更新缓存列表。

以下是几段代码:

    public class MemCachedCache:ICacheProvider
    {
        private static NorthScaleClient client;

        static MemCachedCache()
        {
            try
            {
                client = new NorthScaleClient();
            }
            catch (Exception ex)
            {
                log4net.LogManager.GetLogger("northscale").Info("EnyimMemcachedProvider", ex);
            }            
        }

        #region Implementation of ICacheProvider

        /// <summary>
        /// 获得缓存内容
        /// </summary>
        /// <param name="cacheKey">缓存键</param>
        /// <returns>缓存内容</returns>
        public string GetCache(string cacheKey)
        {
            if (client == null)
            {
                return null;
            }
            else
            {
                object v = client.Get(cacheKey);
                return v == null ? null:v.ToString();
            }
        }

        /// <summary>
        /// 设置缓存内容
        /// </summary>
        /// <param name="cacheKey">缓存键</param>
        /// <param name="cacheContent">缓存内容</param>
        /// <param name="duration">缓存有效时间,分钟</param>
        public void SetCache(string cacheKey, string cacheContent, int duration)
        {
            if (client != null)
            {
                client.Store(StoreMode.Set, cacheKey, cacheContent, new TimeSpan(0, 0, duration*60));
                UpdateCacheItems(cacheKey);
            }
        }

        /// <summary>
        /// 清除缓存内容
        /// </summary>
        /// <param name="cacheKey">缓存键</param>
        public void ClearCache(string cacheKey)
        {
            if (client != null)
            {
                client.Remove(cacheKey);
            }
        }

        /// <summary>
        /// 清除部分缓存
        /// </summary>
	/// <param name="pattern">部分清除模板</param>
        public void ClearCacheByPattern(string pattern)
        {
            if(client!=null)
            {
                object c = client.Get("globel_cacheitems");
                if (c!=null)
                {
                    List<string> cacheitems = (List<string>) c;
                    foreach (string cacheitem in cacheitems)
                    {
                        if (cacheitem.StartsWith(pattern))
                        {
                            client.Remove(cacheitem);
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 清除所有缓存
        /// </summary>
        public void ClearAllCache()
        {
            client.FlushAll();
        }

        /// <summary>
        /// 更新缓存项列边
        /// </summary>
        /// <param name="key">要填加的key</param>
        public void UpdateCacheItems(string key)
        {
            List<string> cacheitems;
            CasResult<object> c = client.GetWithCas("globel_cacheitems");
            //判断列表项缓存是否存在
            if(c.Cas>0)
            {
                cacheitems = (List<string>) c.Result;
                //判断列表中有没有这个key
                if (!cacheitems.Contains(key))
                {
                    cacheitems.Add(key);
                    //判断是否保存成功,这里递归操作并使用Cas,是为了避免并发状态下造成缓存列表竞争,保证最终更新成功
                    if (!client.Cas(StoreMode.Set, "globel_cacheitems", cacheitems, c.Cas).Result)
                    {
                        UpdateCacheItems(key);
                    }
                }
            }
            else
            {
                cacheitems =new List<string>();
                cacheitems.Add(key);
                client.Store(StoreMode.Set, "globel_cacheitems", cacheitems);
            }
        }
        #endregion
    }