Ejemplo n.º 1
0
        public RedisAdaptor(List<EndPoint> endPoints)
        {
            var config = new ConfigurationOptions()
            {
                AllowAdmin = true,
            };

            foreach (var endPoint in endPoints)
            {
                config.EndPoints.Add(endPoint);
            }

            muxerInstance = ConnectionMultiplexer.Connect(config);

            Handle = muxerInstance.GetDatabase();

            var script = Load("update_multikeys_multifields.lua");

            //todo a hack way .. to be changed later
            foreach (var endPoint in muxerInstance.GetEndPoints())
            {
                var server = muxerInstance.GetServer(endPoint);

                updateScriptSha = server.ScriptLoad(script);
            }

            Handle.StringSet("test", "111");
        }
        public RedisStorage(string connectionString, RedisStorageOptions options = null)
        {
            if (connectionString == null) throw new ArgumentNullException("connectionString");
            if (options == null) options = new RedisStorageOptions();

            _connectionMultiplexer = ConnectionMultiplexer.Connect(connectionString);
            _invisibilityTimeout = options.InvisibilityTimeout;
            var endpoint = _connectionMultiplexer.GetEndPoints()[0];
            if (endpoint is IPEndPoint)
            {
                var ipEp = endpoint as IPEndPoint;
                ConnectionString = string.Format("{0}:{1}", TryGetHostName(ipEp.Address), ipEp.Port);
            }
            else
            {
                var dnsEp = endpoint as DnsEndPoint;
                ConnectionString = string.Format("{0}:{1}", dnsEp.Host, dnsEp.Port);
            }

            Db = options.Db;
            if (Prefix != options.Prefix)
            {
                Prefix = options.Prefix;
            }
            identity = Guid.NewGuid().ToString();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets the servers.
 /// </summary>
 /// <param name="muxer">The muxer.</param>
 /// <returns>The list of servers.</returns>
 public IEnumerable <StackRedis.IServer> GetServers(StackRedis.ConnectionMultiplexer muxer)
 {
     EndPoint[] endpoints = muxer.GetEndPoints();
     foreach (var endpoint in endpoints)
     {
         var server = muxer.GetServer(endpoint);
         yield return(server);
     }
 }
		public RedisStorage(string connectionString, int db, TimeSpan invisibilityTimeout)
		{
			if (connectionString == null) throw new ArgumentNullException("connectionString");
			if (invisibilityTimeout == null) throw new ArgumentNullException("invisibilityTimeout");

			_connectionMultiplexer = ConnectionMultiplexer.Connect(connectionString);
			_invisibilityTimeout = invisibilityTimeout;
			var endpoint = _connectionMultiplexer.GetEndPoints()[0];
			if (endpoint is IPEndPoint)
			{
				var ipEp = endpoint as IPEndPoint;
				ConnectionString = string.Format("{0}:{1}", TryGetHostName(ipEp.Address), ipEp.Port);
			}
			else 
			{
				var dnsEp = endpoint as DnsEndPoint;
				ConnectionString = string.Format("{0}:{1}", dnsEp.Host, dnsEp.Port);
			}
			
			Db = db;

		}
        internal static IServer TryGetServer(ConnectionMultiplexer muxer, bool checkConnected = true)
        {
            if (muxer != null)
            {
                var eps = muxer.GetEndPoints(true);
                foreach (var ep in eps)
                {
                    var server = muxer.GetServer(ep);
                    if (server.IsSlave) continue;
                    if (checkConnected && !server.IsConnected) continue;

                    // that'll do
                    return server;
                }
            }
            return null;
        }
Ejemplo n.º 6
0
		internal static string GetHost(ConnectionMultiplexer cache)
		{
			var endPoint = cache.GetEndPoints()[0];

			var dnsEndPoint = endPoint as DnsEndPoint;

			if (dnsEndPoint != null)
			{
				return String.Format("{0}:{1}", dnsEndPoint.Host, dnsEndPoint.Port);
			}

			var ipEndPoint = endPoint as IPEndPoint;

			if (ipEndPoint != null)
			{
				return String.Format("{0}:{1}", ipEndPoint.Address, ipEndPoint.Port);
			}

			return endPoint.ToString();
		}
Ejemplo n.º 7
0
 internal static IServer GetServer(ConnectionMultiplexer conn)
 {
     return conn.GetServer(conn.GetEndPoints()[0]);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Flushes the database that the connection belongs to.
 /// </summary>
 /// <param name="connection">
 /// The connection.
 /// </param>
 public void FlushDatabase(ConnectionMultiplexer connection)
 {
     EndPoint[] endPoints = connection.GetEndPoints();
     foreach (var endPoint in endPoints)
     {
         connection.GetServer(endPoint).FlushDatabase(this.Db);
     }
 }
 public void SetUp()
 {
     redis = ConnectionMultiplexer.Connect("localhost,resolvedns=1,allowadmin=1,connectTimeout=10000");
     endpoint = redis.GetEndPoints().First();
 }