예제 #1
0
        /// <summary>
        /// 获取有效的memcached服务器地址(用于检查所有memcached服务器是否正常工作)
        /// </summary>
        /// <returns>有效的服务器地</returns>
        public static string[] GetConnectedSocketHost()
        {
            SockIO sock          = null;
            string connectedHost = null;

            foreach (string hostName in serverList)
            {
                if (!string.IsNullOrEmpty(hostName))
                {
                    try
                    {
                        //创建链接到某memcached的socket对象
                        sock = SockIOPool.GetInstance(MemCachedConfig.PoolName).GetConnection(hostName);
                        if (sock != null)
                        {
                            //如创建成功则意味着该memcached可用
                            connectedHost = viviLib.Text.Strings.MergeString(hostName, connectedHost);
                        }
                    }
                    finally
                    {
                        if (sock != null)
                        {
                            sock.Close();
                        }
                    }
                }
            }
            return(connectedHost.Split(',')); // Utils.SplitString(connectedHost, ",");
        }
예제 #2
0
        /// <summary>
        /// 获取当前缓存键值所存储在的服务器
        /// </summary>
        /// <param name="key">当前缓存键</param>
        /// <returns>当前缓存键值所存储在的服务器</returns>
        public static string GetSocketHost(string key, object hashCode)
        {
            string hostName = "";
            SockIO sock     = null;

            try
            {
                sock = SockIOPool.GetInstance(MemCachedConfig.PoolName).GetSock(key, hashCode);
                if (sock != null)
                {
                    hostName = sock.Host;
                }
            }
            finally
            {
                if (sock != null)
                {
                    sock.Close();
                }
            }
            return(hostName);
        }