Exemplo n.º 1
0
        internal WorkflowManagement(ConnectionMultiplexer mux, ITaskHandler taskHandler, WorkflowHandler workflowHandler, string identifier, IEnumerable<string> typesProcessed, ILua lua, EventHandler<Exception> exceptionHandler = null, Behaviours behaviours = Behaviours.All)
        {
            _taskHandler = taskHandler;

            _workflowHandler = workflowHandler;

            if (exceptionHandler != null)
            {
                ExceptionThrown += exceptionHandler;
            }

            _typesProcessed = typesProcessed;

            _db = mux.GetDatabase();

            _sub = mux.GetSubscriber();

            if (_typesProcessed == null || _typesProcessed.Count() == 0)
            {
                _sub.Subscribe("submittedTask", (c, v) =>
                {
                    ProcessNextTask();
                });
            }
            else
            {
                foreach(var t in _typesProcessed)
                {
                    _sub.Subscribe("submittedTask:" + t, (c, v) =>
                    {
                        ProcessNextTask(t);
                    });
                }
            }

            _sub.Subscribe("workflowFailed", (c, v) =>
            {
                ProcessNextFailedWorkflow();
            });

            _sub.Subscribe("workflowComplete", (c, v) =>
            {
                ProcessNextCompleteWorkflow();
            });

            _lua = lua;
            _lua.LoadScripts(_db, mux.GetServer("localhost:6379"));

            _identifier = identifier;

            if (behaviours.HasFlag(Behaviours.AutoRestart))
            {
                var resubmittedTasks = ResubmitTasks();

                foreach (var item in resubmittedTasks)
                {
                    Console.WriteLine("Resubmitted {0}", item);
                }
            }
        }
        public WatcherManager(IEnumerable<WatchGroup> groups)
        {
            var groupList = groups.ToList();
            var config = new ConfigurationOptions()
            {
                AllowAdmin = true,
            };

            foreach (var group in groupList)
            {
                config.EndPoints.Add(group.Master.EndPoint);
            }

            muxerInstance = ConnectionMultiplexer.Connect(config);
            muxerInstance.ConnectionRestored += MuxerInstanceOnConnectionRestored;

            foreach (var group in groupList)
            {
                var server = muxerInstance.GetServer(group.Master.EndPoint);
                var epStr = server.EndPoint.ToString();

                group.Master.Server = server;
                group.Master.OnPing(TimeSpan.Zero);

                Program.zkAdaptor.Identity(group.Master.EndPoint.ToString());
                this.groups.Add(epStr, group);
                redisInstancesDict.Add(epStr, group.Master);
            }
        }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
0
        static void CleanRedis()
        {
            connection = Redis.ConnectionMultiplexer.Connect("localhost,allowAdmin=true");

            server = connection.GetServer("localhost", 6379);
            server.FlushDatabase();

            db = connection.GetDatabase();
        }
Exemplo n.º 5
0
        private static IEnumerable<RedisKey> FetchAllKeys(ConnectionMultiplexer multiplexer, EndPoint endpoint)
        {
            var server = multiplexer.GetServer(endpoint);

            var allKeys = server.Keys()
                                .ToArray();

            return allKeys;
        }
Exemplo n.º 6
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);
     }
 }
        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;
        }
Exemplo n.º 8
0
 internal static IServer GetServer(ConnectionMultiplexer conn)
 {
     return conn.GetServer(conn.GetEndPoints()[0]);
 }
Exemplo n.º 9
0
        private void Initialize()
        {
            var options = new ConfigurationOptions()
            {
                AllowAdmin = true,
                ConnectTimeout = 1000,
            };

            var endpoint = new DnsEndPoint(_redisConfig.Host, _redisConfig.Port, AddressFamily.InterNetwork);
            options.EndPoints.Add(endpoint);

            if (!string.IsNullOrEmpty(_redisConfig.Password))
                options.Password = _redisConfig.Password;

            try
            {
                // create the connection
                _connectionMultiplexer = ConnectionMultiplexer.ConnectAsync(options).Result;

                // access to database.
                _database = _connectionMultiplexer.GetDatabase(_redisConfig.DatabaseId);

                // get the configured server.
                _server = _connectionMultiplexer.GetServer(endpoint);

                // check the version
                var version = GetVersion();
                if (version < _requiredMinimumVersion)
                    throw new Exception(string.Format("You are using redis version {0}, minimum required version is 2.6", version));

                _logger.Information("Storage initialized: {0:l}:{1}, v{2:l}.", endpoint.Host, endpoint.Port, version);
            }
            catch (Exception e)
            {
                IsEnabled = false;
                _logger.Error(string.Format("Storage initialization failed: {0:l}:{1}.", endpoint.Host, endpoint.Port));
            }
        }
Exemplo n.º 10
0
 public RedisTests()
 {
     _multiplexer = new RedisDatabase().GetDatabase().Multiplexer;
     _server = _multiplexer.GetServer("localhost", 6379);
 }
Exemplo n.º 11
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);
     }
 }
 /// <summary>
 /// Provide an alternate ConnectionMultiplexer to use for INFO command
 /// </summary>
 /// <param name="Connection"></param>
 /// <param name="title">Title to appear on the dashboard</param>
 /// <param name="key">Redis INFO key</param>
 /// <returns></returns>
 public DashboardMetric GetDashboardInfo(ConnectionMultiplexer Connection, string title, string key)
 {
     return GetDashboardInfo(Connection.GetServer(Connection.GetDatabase(Db).IdentifyEndpoint()), title, key);
 }
Exemplo n.º 13
0
        private void ReconfigureConnection(List<RedisInstanceBase> toConnect)
        {
            var config = ConfigurationOptions.Parse(muxerInstance.Configuration);

            foreach (var ins in toConnect)
            {
                config.EndPoints.Add(ins.EndPoint);
            }

            lock (muxerSyncLock)
            {
                muxerInstance.Dispose();
                muxerInstance = ConnectionMultiplexer.Connect(config);

                RefreshAll();

                muxerInstance.ConnectionRestored += MuxerInstanceOnConnectionRestored;
            }

            foreach (var ins in toConnect)
            {
                ins.Server = muxerInstance.GetServer(ins.EndPoint);
            }
        }
Exemplo n.º 14
0
        private void Initialize()
        {
            var options = new ConfigurationOptions();
            var endpoint = new DnsEndPoint(Config.Host, Config.Port, AddressFamily.InterNetwork);
            options.EndPoints.Add(endpoint);
            options.AllowAdmin = true;
            if (!string.IsNullOrEmpty(Config.Password))
                options.Password = Config.Password;

            try
            {
                // create the connection
                _connectionMultiplexer = ConnectionMultiplexer.ConnectAsync(options).Result;

                // access to database.
                _database = _connectionMultiplexer.GetDatabase(Config.DatabaseId);

                // get the configured server.
                _server = _connectionMultiplexer.GetServer(endpoint);

                // check the version
                var info = _server.Info();
                Version version = null;
                foreach (var pair in info[0])
                {
                    if (pair.Key == "redis_version")
                    {
                        version = new Version(pair.Value);
                        if (version < _requiredMinimumVersion)
                            throw new Exception(string.Format("You are using redis version {0}, minimum required version is 2.6", version));

                        break;
                    }
                }

                Log.ForContext<Redis>().Information("Storage initialized: {0}, v{1}.", endpoint, version);
            }
            catch (Exception e)
            {
                IsEnabled = false;
                Log.ForContext<Redis>().Error(e, string.Format("Storage initialization failed: {0}", endpoint));
            }
        }