public RedisConnectionManager(IRedisServerSettings settings, IRedisConnection redisConnection)
 {
     this.settings = settings;
     //this.connectionString = new Lazy<string>(GetConnectionString);
     //this.connectionString = GetConnectionString();
     this.connection = redisConnection;
 }
        public ClearExpiredMessagesLua(IRedisConnection connection, RedisNames redisNames)
            : base(connection, redisNames)
        {
            Script = @"local uuids = redis.call('zrangebyscore', @expirekey, 0, @currenttime, 'LIMIT', 0, @limit)
                        if #uuids == 0 then
	                        return 0
                        end
                        local inProgress = 0
                        for k, v in pairs(uuids) do       
                            local inPending = redis.call('LREM', @pendingkey, -1, v)
                            if(inPending == 1) then                                             
	                            redis.call('hdel', @valueskey, v) 
                                redis.call('hdel', @headerskey, v) 
                                redis.call('hdel', @Statuskey, v) 
	                            redis.call('hdel', @metakey, v) 
	                            redis.call('LREM', @errorkey, -1, v) 
	                            redis.call('zrem', @delaykey, v) 
	                            redis.call('zrem', @expirekey, v) 

                                 local jobName = redis.call('hget', @JobIDKey, v) 
                                 if (jobName) then
                                    redis.call('hdel', @JobIDKey, v) 
                                    redis.call('hdel', @JobKey, jobName) 
                                 end
                            else 
                                inProgress = inProgress + 1
                            end
                        end
                        return table.getn(uuids) - inProgress";
        }
Exemplo n.º 3
0
        internal RedisMessageBus(IStringMinifier stringMinifier,
                                 ILoggerFactory loggerFactory,
                                 IPerformanceCounterManager performanceCounterManager,
                                 IOptions <MessageBusOptions> optionsAccessor,
                                 IOptions <RedisScaleoutOptions> scaleoutConfigurationAccessor,
                                 IRedisConnection connection,
                                 bool connectAutomatically)
            : base(stringMinifier, loggerFactory, performanceCounterManager, optionsAccessor, scaleoutConfigurationAccessor)
        {
            _connectionString = scaleoutConfigurationAccessor.Options.ConnectionString;
            _db  = scaleoutConfigurationAccessor.Options.Database;
            _key = scaleoutConfigurationAccessor.Options.EventKey;

            _connection = connection;

            _logger = loggerFactory.CreateLogger <RedisMessageBus>();

            ReconnectDelay = TimeSpan.FromSeconds(2);

            if (connectAutomatically)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    var ignore = ConnectWithRetry();
                });
            }
        }
Exemplo n.º 4
0
 public RedisCachingProvider(string connectionName, IConfig <RedisCachingConfig> config, ILogService logService, IRedisConnection connection)
 {
     ConnectionName = connectionName;
     _config        = config;
     _logService    = logService;
     _connection    = connection;
 }
Exemplo n.º 5
0
        /// <inheritdoc />
        public ResetHeartbeatLua(IRedisConnection connection, RedisNames redisNames, IGetTimeFactory getTime, ICompositeSerialization serialization)
            : base(connection, redisNames)
        {
            _getTime       = getTime.Create();
            _serialization = serialization;
            Script         = @"local returnData = {}
                        local uuids = redis.call('zrangebyscore', @workingkey, 0, @heartbeattime, 'LIMIT', 0, @limit)
                        if #uuids == 0 then
	                        return nil
                        end
                        local index = 1
                        for k, v in pairs(uuids) do                             
	                        redis.call('zrem',  @workingkey, v)
                            local routeName = redis.call('hget', @RouteIDKey, v) 
                            if(routeName) then
                                local routePending = @pendingkey .. '_}' .. routeName
                                redis.call('rpush', routePending, v) 
                            else
	                            redis.call('rpush', @pendingkey, v) 
                            end
                            redis.call('hset', @StatusKey, v, '0') 
                            returnData[index] = {v, redis.call('hget', @headerskey, v)}
                            index = index + 1
                        end
                        redis.call('publish', @channel, '') 
                        return returnData";
        }
        internal RedisMessageBus(IDependencyResolver resolver, RedisScaleoutConfiguration configuration, IRedisConnection connection, bool connectAutomatically)
            : base(resolver, configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            _connection = connection;

            _connectionString = configuration.ConnectionString;
            _db  = configuration.Database;
            _key = configuration.EventKey;

            _traceManager = resolver.Resolve <ITraceManager>();

            _trace = _traceManager["SignalR." + nameof(RedisMessageBus)];

            ReconnectDelay = TimeSpan.FromSeconds(2);

            if (connectAutomatically)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    var ignore = ConnectWithRetry();
                });
            }
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        /// <summary>
        /// Initializes a new instance of the <see cref="ResetHeartbeatLua"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        public ResetHeartbeatLua(IRedisConnection connection, RedisNames redisNames)
            : base(connection, redisNames)
        {
            Script = @"local signal = tonumber(@signalID)
                        local uuids = redis.call('zrangebyscore', @workingkey, 0, @heartbeattime, 'LIMIT', 0, @limit)
                        if #uuids == 0 then
	                        return 0
                        end
                        for k, v in pairs(uuids) do                             
	                        redis.call('zrem',  @workingkey, v)
                            local routeName = redis.call('hget', @RouteIDKey, v) 
                            if(routeName) then
                                local routePending = @pendingkey .. '_}' .. routeName
                                redis.call('rpush', routePending, v) 
                            else
	                            redis.call('rpush', @pendingkey, v) 
                            end
                            redis.call('hset', @StatusKey, v, '0') 
	                        if signal == 1 then
		                        redis.call('publish', @channel, v) 
	                        end
                        end

                        if signal == 0 then
	                        redis.call('publish', @channel, '') 
                        end
                        return table.getn(uuids)";
        }
Exemplo n.º 8
0
 internal RedisClient(RedisEndpoint endpoint, IRedisConnection connection)
 {
     this.endpoint                  = endpoint;
     this.connection                = connection;
     this.connection.Connecting    += OnConnecting;
     this.connection.Disconnecting += OnDisconnecting;
 }
Exemplo n.º 9
0
        internal RedisHelper(RedisConfiguration configuration, IRedisConnection connection, bool connectAutomatically)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _connection = connection;
            _connection.ConnectionFailed   += OnConnectionFailed;
            _connection.ConnectionRestored += OnConnectionRestored;
            _connection.ErrorMessage       += OnConnectionError;

            _connectionString = configuration.ConnectionString;
            _db        = configuration.Db;
            _prefixKey = configuration.PrefixKey;

            _trace = new TraceSource(nameof(RedisHelper));

            ReconnectDelay = TimeSpan.FromSeconds(30);

            if (connectAutomatically)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    var ignore = ConnectWithRetry();
                });
            }
        }
Exemplo n.º 10
0
        private RedisRawResponse ExecuteInternal(IRedisConnection connection, bool throwException = true, bool sendNotReceive = false)
        {
            if (connection == null)
            {
                if (throwException)
                {
                    throw new RedisFatalException(new ArgumentNullException("connection"), RedisErrorCode.MissingParameter);
                }
                return(null);
            }

            RedisRawResponse response = RedisVoidResponse.Void;

            if (sendNotReceive || !m_CommandType.HasFlag(RedisCommandType.SendAndReceive))
            {
                connection.Send(this);
            }
            else
            {
                response = connection.SendReceive(this);
                if (ReferenceEquals(response, null) && throwException)
                {
                    throw new RedisException("Corrupted redis response data", RedisErrorCode.CorruptResponse);
                }
                response.HandleError();
            }
            return(response);
        }
Exemplo n.º 11
0
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new instance of the <see cref="ErrorLua"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="redisNames">The redis names.</param>
 public ErrorLua(IRedisConnection connection, RedisNames redisNames)
     : base(connection, redisNames)
 {
     Script = @"redis.call('zrem', @workingkey, @uuid) 
              redis.call('lpush', @errorkey, @uuid) 
              redis.call('hset', @StatusKey, @uuid, '2') ";
 }
Exemplo n.º 12
0
 public RedisMultiBytes ExpectMultiDataBytes(IRedisConnection connection, bool throwException = true)
 {
     using (var response = ExecuteInternal(connection, throwException))
     {
         return(ForMultiDataBytes(response, throwException));
     }
 }
Exemplo n.º 13
0
 public RedisNullableDouble ExpectNullableDouble(IRedisConnection connection, bool throwException = true)
 {
     using (var response = ExecuteInternal(connection, throwException))
     {
         return(ForNullableDouble(response, throwException));
     }
 }
Exemplo n.º 14
0
 public void Initialize(IRedisConnection <ConnectionMultiplexer> connection)
 {
     if (connection != null)
     {
         _client = connection.Connect();
     }
 }
Exemplo n.º 15
0
 public EventBusRedis(IRedisConnection redisConnection, ILifetimeScope lifetimeScope, ILogger <EventBusRedis> logger, IEventBusSubscribeManager eventBusSubscribeManager)
 {
     this.redisConnection          = redisConnection;
     this.lifetimeScope            = lifetimeScope;
     this.logger                   = logger;
     this.eventBusSubscribeManager = eventBusSubscribeManager;
 }
Exemplo n.º 16
0
        private async Task <bool> CheckIfUserIsAuthored(string login, string password)
        {
            this._connection = new RedisConnection();
            var data = await this._connection.GetStringFromDatabase(login);

            return(data.Value == password && data.Key == login);
        }
Exemplo n.º 17
0
        public RedisEventStore(IMessageQueue messageQueue, IRedisConnection redis)
        {
            _messageQueue = messageQueue;
            _redis        = redis;

            Streams = Observable.Create(async(IObserver <IStream> observer) =>
            {
                var values = await Db.HashValuesAsync(_streamsKey);
                foreach (var value in values)
                {
                    var stream = JsonConvert.DeserializeObject <IStream>(value, JsonSerializerSettings);
                    observer.OnNext(stream);
                }
                observer.OnCompleted();
            }).Concat(_streams);

            BatchStreams = Observable.Create(async(IObserver <List <IStream> > observer) =>
            {
                var values  = await Db.HashValuesAsync(_streamsKey);
                var streams = values.Select(s => JsonConvert.DeserializeObject <IStream>(s, JsonSerializerSettings))
                              .ToList();
                observer.OnNext(streams);
                observer.OnCompleted();
            }).Concat(_streams.Select(s => new List <IStream> {
                s
            }));
        }
Exemplo n.º 18
0
        internal RedisMessageBus(IDependencyResolver resolver, RedisScaleoutConfiguration configuration, IRedisConnection connection, bool connectAutomatically)
            : base(resolver, configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            _connection = connection;

            _connectionString = configuration.ConnectionString;
            _db = configuration.Database;
            _key = configuration.EventKey;

            var traceManager = resolver.Resolve<ITraceManager>();

            _trace = traceManager["SignalR." + typeof(RedisMessageBus).Name];

            ReconnectDelay = TimeSpan.FromSeconds(2);

            if (connectAutomatically)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    var ignore = ConnectWithRetry();
                });
            }
        }
Exemplo n.º 19
0
 public DatabaseItem(IRedisConnection cont, string cntName, string dbName, string dbInfo = "")
     : base(cont, cntName)
 {
     DbName = dbName;
     DbInfo = dbInfo;
     DbIndex = DbName.GetNumber().ToInt32(0);
 }
Exemplo n.º 20
0
        /// <inheritdoc />
        /// <summary>
        /// Initializes a new instance of the <see cref="DeleteLua"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        public DeleteLua(IRedisConnection connection, RedisNames redisNames)
            : base(connection, redisNames)
        {
            Script = @"redis.call('zrem', @workingkey, @uuid) 
                     redis.call('hdel', @valueskey, @uuid) 
                     redis.call('hdel', @headerskey, @uuid) 
                     redis.call('hdel', @metakey, @uuid) 
                     redis.call('LREM', @pendingkey, -1, @uuid) 
                     redis.call('LREM', @errorkey, -1, @uuid) 
                     redis.call('zrem', @delaykey, @uuid) 
                     redis.call('zrem', @errortimekey, @uuid) 
                     redis.call('zrem', @expirekey, @uuid) 
                     redis.call('hdel', @StatusKey, @uuid) 

                     local jobName = redis.call('hget', @JobIDKey, @uuid) 
                     if (jobName) then
                        redis.call('hdel', @JobIDKey, @uuid) 
                        redis.call('hdel', @JobKey, jobName) 
                     end
                     local routeName = redis.call('hget', @RouteIDKey, @uuid) 
                     if(routeName) then
                         redis.call('hdel', @RouteIDKey, @uuid) 
                     end
                     return 1";
        }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ErrorLua"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="redisNames">The redis names.</param>
 public ErrorLua(IRedisConnection connection, RedisNames redisNames)
     : base(connection, redisNames)
 {
     Script = @"redis.call('zrem', @workingkey, @uuid) 
              redis.call('lpush', @errorkey, @uuid) 
              redis.call('hset', @StatusKey, @uuid, '2') ";
 }
        /// <inheritdoc />
        /// <summary>
        /// Initializes a new instance of the <see cref="MoveDelayedToPendingLua"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        public MoveDelayedToPendingLua(IRedisConnection connection, RedisNames redisNames)
            : base(connection, redisNames)
        {
            Script = @"local signal = tonumber(@signalID)
                       local uuids = redis.call('zrangebyscore', @delaykey, 0, @currenttime, 'LIMIT', 0, @limit)
                       if #uuids == 0 then
                        return 0
                       end

                       for k, v in pairs(uuids) do                             
                        redis.call('zrem',  @delaykey, v)
                        
                        local routeName = redis.call('hget', @RouteIDKey, v) 
                        if(routeName) then
                            local routePending = @pendingkey .. '_}' .. routeName
                            redis.call('lpush', routePending, v) 
                        else
                            redis.call('lpush', @pendingkey, v) 
                        end
                        if signal == 1 then
                            redis.call('publish', @channel, v) 
                        end
                       end

                        if signal == 0 then
                            redis.call('publish', @channel, '') 
                        end
                      return table.getn(uuids)";
        }
Exemplo n.º 23
0
        /// <inheritdoc />
        /// <summary>
        /// Initializes a new instance of the <see cref="EnqueueExpirationLua"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        public EnqueueExpirationLua(IRedisConnection connection, RedisNames redisNames)
            : base(connection, redisNames)
        {
            Script = @"local id = @field
                    
                     if id == '' then
                        id = redis.call('INCR', @IDKey)
                     end

                     local signal = tonumber(@signalID)
                     redis.call('hset', @key, id, @value) 
                     redis.call('hset', @headerskey, id, @headers) 
                     redis.call('lpush', @pendingkey, id) 
                     redis.call('zadd', @expirekey, @timestampexpire, id) 
                     redis.call('hset', @metakey, id, @metavalue) 
                     redis.call('hset', @StatusKey, id, '0') 
                      if @Route ~= '' then
                         redis.call('hset', @RouteIDKey, id, @Route)
                     end
                      if signal == 1 then
                        redis.call('publish', @channel, id) 
                     else
                        redis.call('publish', @channel, '') 
                     end
                     return id";
        }
Exemplo n.º 24
0
        public RedisResponse Execute(IRedisConnection connection)
        {
            if (connection.IsPassThrough)
            {
                throw new InvalidOperationException($"Connection is marked as Pass-Through and will not execute command \"{command}\".");
            }
            if (!connection.IsOpen)
            {
                throw new InvalidOperationException($"Connection is not open or has been closed. Command \"{command}\" will not be executed.");
            }

            var bytes   = GenerateCommand(collection.ToArray());
            var channel = connection.RedisChannel;

            try
            {
                channel.Write(bytes, 0, bytes.Length);
                channel.Flush();

                var parser = new RedisResponseParser(channel);
                return(parser.Parse());
            }
            catch (Exception ex)
            {
                connection.Dispose();
                throw ex;
            }
        }
Exemplo n.º 25
0
 public PipelinedCommandExecutor(IRedisConnection conn)
 {
     _conn       = conn;
     _reader     = new RedisReader(_conn.Reader);
     _readThread = new Thread(ReadProcedure);
     _readThread.Start();
 }
 public PipelinedCommandExecutor(IRedisConnection conn)
 {
     _conn = conn;
     _reader = new RedisReader(_conn.Reader);
     _readThread = new Thread(ReadProcedure);
     _readThread.Start();
 }
Exemplo n.º 27
0
        internal RedisMessageBus(IStringMinifier stringMinifier,
                                     ILoggerFactory loggerFactory,
                                     IPerformanceCounterManager performanceCounterManager,
                                     IOptions<MessageBusOptions> optionsAccessor,
                                     IOptions<RedisScaleoutOptions> scaleoutConfigurationAccessor,
                                     IRedisConnection connection,
                                     bool connectAutomatically)
            : base(stringMinifier, loggerFactory, performanceCounterManager, optionsAccessor, scaleoutConfigurationAccessor)
        {
            _connectionString = scaleoutConfigurationAccessor.Options.ConnectionString;
            _db = scaleoutConfigurationAccessor.Options.Database;
            _key = scaleoutConfigurationAccessor.Options.EventKey;

            _connection = connection;

            _logger = loggerFactory.CreateLogger<RedisMessageBus>();

            ReconnectDelay = TimeSpan.FromSeconds(2);

            if (connectAutomatically)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    var ignore = ConnectWithRetry();
                });
            }
        }
Exemplo n.º 28
0
 public RollbackDelayLua(IRedisConnection connection, RedisNames redisNames)
     : base(connection, redisNames)
 {
     Script = @"redis.call('zrem', @workingkey, @uuid) 
                redis.call('zadd', @delaykey, @timestamp, @uuid) 
                redis.call('hset', @StatusKey, @uuid, '0') 
                return 1";
 }
Exemplo n.º 29
0
 public RedisMessageBus(IStringMinifier stringMinifier,
                              ILoggerFactory loggerFactory,
                              IPerformanceCounterManager performanceCounterManager,
                              IOptions<MessageBusOptions> optionsAccessor,
                              IOptions<RedisScaleoutOptions> scaleoutConfigurationAccessor, IRedisConnection connection)
     : this(stringMinifier, loggerFactory, performanceCounterManager, optionsAccessor, scaleoutConfigurationAccessor, connection, true)
 {
 }
Exemplo n.º 30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseLua"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        protected BaseLua(IRedisConnection connection, RedisNames redisNames)
        {
            Guard.NotNull(() => connection, connection);
            Guard.NotNull(() => redisNames, redisNames);

            Connection = connection;
            RedisNames = redisNames;
        }
Exemplo n.º 31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseLua"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        protected BaseLua(IRedisConnection connection, RedisNames redisNames)
        {
            Guard.NotNull(() => connection, connection);
            Guard.NotNull(() => redisNames, redisNames);

            Connection = connection;
            RedisNames = redisNames;
        }
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new instance of the <see cref="RollbackDelayLua"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="redisNames">The redis names.</param>
 public RollbackDelayLua(IRedisConnection connection, RedisNames redisNames)
     : base(connection, redisNames)
 {
     Script = @"redis.call('zrem', @workingkey, @uuid) 
                redis.call('zadd', @delaykey, @timestamp, @uuid) 
                redis.call('hset', @StatusKey, @uuid, '0') 
                return 1";
 }
Exemplo n.º 33
0
        public RedisAuthenticationSessionStore(IRedisConnection redisConnection, IAuthenticationTicketSerializer serializer)
        {
            Guard.Against <ArgumentNullException>(redisConnection.IsNull(), "redisConnection can't be null");
            Guard.Against <ArgumentNullException>(serializer.IsNull(), "serializer can't be null");

            this.redisConnection = redisConnection;
            this.serializer      = serializer;
        }
Exemplo n.º 34
0
 public RedisCacheStore(IRedisConnection connection, IRedisServerSettings settings)
 {
     _connection = connection;
     _subscriber = _connection.GetSubscriber();
     _database   = _connection.GetDatabase();
     _server     = _connection.GetServer(_connection.GetEndPoints().FirstOrDefault());
     _settings   = settings;
 }
 public RedisDistributedCacheLock(string key, RedisDistributedLockProviderOptions options)
 {
     this.connection        = options.Connection;
     this.lockKey           = "LOCK_" + key;
     this.timeout           = options.Timeout;
     this.retryDelay        = options.RetryDelay;
     this.exceptionNotifier = options.ExceptionNotifier;
 }
Exemplo n.º 36
0
 public RedisRepo(
     IRedisConnection con,
     IRedisConfig config,
     IJsonService json)
 {
     _con    = con;
     _config = config;
     _json   = json;
 }
Exemplo n.º 37
0
        protected NodeRoleAndSiblings GetNodeInfo(string masterName, IRedisConnection connection)
        {
            if (connection != null)
            {
                try
                {
                    var serverInfo = connection.GetServerInfo();
                    if (serverInfo != null)
                    {
                        var role = DiscoverRoleOfNode(serverInfo);

                        switch (role)
                        {
                        case RedisRole.Slave:
                            return(GetMasterOfSlave(serverInfo) ?? new NodeRoleAndSiblings(role, null));

                        case RedisRole.Master:
                            return(GetSlavesOfMaster(serverInfo) ?? new NodeRoleAndSiblings(role, null));

                        case RedisRole.Sentinel:
                        {
                            var masters = GetMastersOfSentinel(masterName, serverInfo);
                            if (!Disposed)
                            {
                                var otherSentinels = GetSiblingSentinelsOfSentinel(masterName, connection);
                                if (!Disposed)
                                {
                                    if (otherSentinels == null || otherSentinels.Siblings == null)
                                    {
                                        return(masters ?? new NodeRoleAndSiblings(role, null));
                                    }

                                    if (masters == null || masters.Siblings == null)
                                    {
                                        return(otherSentinels ?? new NodeRoleAndSiblings(role, null));
                                    }

                                    var siblings = new HashSet <RedisEndPoint>(masters.Siblings);
                                    siblings.UnionWith(otherSentinels.Siblings);

                                    return(new NodeRoleAndSiblings(role, siblings.ToArray()));
                                }
                            }
                            break;
                        }

                        default:
                            break;
                        }
                    }
                }
                catch (Exception)
                { }
            }
            return(null);
        }
Exemplo n.º 38
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GetJobIdQueryHandler" /> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        public GetJobIdQueryHandler(
            IRedisConnection connection,
            RedisNames redisNames)
        {
            Guard.NotNull(() => connection, connection);
            Guard.NotNull(() => redisNames, redisNames);

            _connection = connection;
            _redisNames = redisNames;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GetPendingDelayedCountQueryHandler" /> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        public GetPendingDelayedCountQueryHandler(
            IRedisConnection connection,
            RedisNames redisNames)
        {
            Guard.NotNull(() => connection, connection);
            Guard.NotNull(() => redisNames, redisNames);

            _connection = connection;
            _redisNames = redisNames;
        }
Exemplo n.º 40
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="redisConnection"></param>
 public DistributedCacheService(IDistributedCache cache, IRedisConnection redisConnection)
 {
     _cache                  = cache;
     _redisConnection        = redisConnection;
     _jsonSerializerSettings = new JsonSerializerSettings
     {
         ReferenceLoopHandling      = ReferenceLoopHandling.Serialize,
         PreserveReferencesHandling = PreserveReferencesHandling.Objects
     };
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisJobSchedulerLastKnownEvent" /> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        public RedisJobSchedulerLastKnownEvent(
            IRedisConnection connection,
            RedisNames redisNames)
        {
            Guard.NotNull(() => connection, connection);
            Guard.NotNull(() => redisNames, redisNames);

            _connection = connection;
            _redisNames = redisNames;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisQueueWorkSubFactory" /> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        /// <param name="cancelWork">The cancel work.</param>
        public RedisQueueWorkSubFactory(IRedisConnection connection,
            RedisNames redisNames,
            IQueueCancelWork cancelWork)
        {
            Guard.NotNull(() => connection, connection);
            Guard.NotNull(() => redisNames, redisNames);
            Guard.NotNull(() => cancelWork, cancelWork);

            _connection = connection;
            _redisNames = redisNames;
            _cancelWork = cancelWork;
        }
Exemplo n.º 43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RollbackLua"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="redisNames">The redis names.</param>
 public RollbackLua(IRedisConnection connection, RedisNames redisNames)
     : base(connection, redisNames)
 {
     Script = @"local signal = tonumber(@signalID)
              redis.call('zrem', @workingkey, @uuid) 
              redis.call('rpush', @pendingkey, @uuid) 
              redis.call('hset', @StatusKey, @uuid, '0') 
              if signal == 1 then
                redis.call('publish', @channel, @uuid) 
              else
                 redis.call('publish', @channel, '') 
              end
              return 1";
 }
 public void Dispose()
 {
     if (_conn != null)
     {
         lock (_evts)
         {
             _stopReading = true;
             Monitor.Pulse(_evts);
         }
         _readThread.Join();
         _conn.Dispose();
         _conn = null;
     }
 }
Exemplo n.º 45
0
 public DequeueRpcLua(IRedisConnection connection, RedisNames redisNames)
     : base(connection, redisNames)
 {
     Script= @"local count = redis.call('LREM', @pendingkey, 1, @uuid) 
             if (count==0) then 
                 return nil;
             end                   
             local expireScore = redis.call('zscore', @expirekey, @uuid)
             redis.call('zadd', @workingkey, @timestamp, @uuid) 
             local message = redis.call('hget', @valueskey, @uuid) 
             redis.call('hset', @StatusKey, @uuid, '1') 
             local headers = redis.call('hget', @headerskey, @uuid)
             return {@uuid, message, headers, expireScore}";
 }
Exemplo n.º 46
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisQueueCreation" /> class.
        /// </summary>
        /// <param name="connectionInfo">The connection information.</param>
        /// <param name="redisConnection">The redis connection.</param>
        /// <param name="redisNames">The redis names.</param>
        /// <param name="creationScope">The creation scope.</param>
        public RedisQueueCreation(IConnectionInformation connectionInfo,
            IRedisConnection redisConnection,
            RedisNames redisNames,
            ICreationScope creationScope)
        {
            Guard.NotNull(() => connectionInfo, connectionInfo);
            Guard.NotNull(() => redisConnection, redisConnection);
            Guard.NotNull(() => redisNames, redisNames);
            Guard.NotNull(() => creationScope, creationScope);

            _redisConnection = redisConnection;
            _redisNames = redisNames;
            ConnectionInfo = connectionInfo;
            Scope = creationScope;
        }
        public ExistingRedisConnectionTests()
        {
            //mock of subscriber
            mockOfSubscriber = new Mock<ISubscriber>();
            mockOfSubscriber.Setup(s => s.UnsubscribeAll(It.IsAny<CommandFlags>()));
            mockOfSubscriber.Setup(s => s.Subscribe(It.IsAny<RedisChannel>(), It.IsAny<Action<RedisChannel, RedisValue>>(), It.IsAny<CommandFlags>()));
            mockOfSubscriber.Setup(s => s.PublishAsync(It.IsAny<RedisChannel>(), It.IsAny<RedisValue>(), It.IsAny<CommandFlags>())).ReturnsAsync(10L);
            //mock of mux
            mockOfMux = new Mock<IConnectionMultiplexer>();
            mockOfMux.Setup(c => c.IsConnected).Returns(true);
            mockOfMux.Setup(c => c.Close(false));
            mockOfMux.Setup(c => c.GetSubscriber(It.IsAny<object>())).Returns(this.mockOfSubscriber.Object);

            cnx = new ExistingRedisConnnection(mockOfMux.Object);
        }
Exemplo n.º 48
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EnqueueDelayedLua"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="redisNames">The redis names.</param>
 public EnqueueDelayedLua(IRedisConnection connection, RedisNames redisNames)
     : base(connection, redisNames)
 {
     Script = @" local id = @field
             
              if id == '' then
                 id = redis.call('INCR', @IDKey)
              end
              redis.call('hset', @key, id, @value) 
              redis.call('hset', @headerskey, id, @headers) 
              redis.call('zadd', @delaykey, @timestamp, id) 
              redis.call('hset', @metakey, id, @metavalue) 
              redis.call('hset', @StatusKey, id, '0') 
              return id";
 }
Exemplo n.º 49
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisQueueWorkSubRpc"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        /// <param name="cancelWork">The cancel work.</param>
        /// <param name="messageId">The message identifier.</param>
        public RedisQueueWorkSubRpc(IRedisConnection connection,
            RedisNames redisNames,
            IQueueCancelWork cancelWork,
            IMessageId messageId)
        {
            Guard.NotNull(() => connection, connection);
            Guard.NotNull(() => redisNames, redisNames);
            Guard.NotNull(() => cancelWork, cancelWork);

            _connection = connection;
            _redisNames = redisNames;
            _cancelWork = cancelWork;
            _messageId = messageId;

            _waitHandle = new ManualResetEventSlim(false);
            _waitHandle.Set();
        }
Exemplo n.º 50
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DoesJobExistLua"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="redisNames">The redis names.</param>
 public DoesJobExistLua(IRedisConnection connection, RedisNames redisNames)
     : base(connection, redisNames)
 {
     Script = @"local jobExists = redis.call('hget', @JobJey, @JobName) 
              if(jobExists) then
                 local alreadyScheduledAndRan = redis.call('hget', @JobEventKey, @JobNameScheduled)
                 if (alreadyScheduledAndRan == @ScheduledTime) then
                     return 3
                 else
                     return redis.call('hget', @StatusKey, jobExists)
                 end
              end
              local alreadyScheduledAndRan = redis.call('hget', @JobEventKey, @JobNameScheduled)
              if (alreadyScheduledAndRan == @ScheduledTime) then
                  return 3
              end
              return -1";
 }
Exemplo n.º 51
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DequeueLua"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="redisNames">The redis names.</param>
 public DequeueLua(IRedisConnection connection, RedisNames redisNames)
     : base(connection, redisNames)
 {
     Script= @"local uuid = redis.call('rpop', @pendingkey) 
             if (uuid==false) then 
                 return nil;
             end        
             local expireScore = redis.call('zscore', @expirekey, uuid)
             local message = redis.call('hget', @valueskey, uuid) 
             local headers = redis.call('hget', @headerskey, uuid)
             if(message) then
                 redis.call('zadd', @workingkey, @timestamp, uuid)
                 redis.call('hset', @StatusKey, uuid, '1') 
                 return {uuid, message, headers, expireScore} 
             else
                 return {uuid, '', '', ''}
             end";
             
 }
Exemplo n.º 52
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeleteLua"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        public DeleteLua(IRedisConnection connection, RedisNames redisNames)
            : base(connection, redisNames)
        {
            Script= @"redis.call('zrem', @workingkey, @uuid) 
                     redis.call('hdel', @valueskey, @uuid) 
                     redis.call('hdel', @headerskey, @uuid) 
                     redis.call('hdel', @metakey, @uuid) 
                     redis.call('LREM', @pendingkey, -1, @uuid) 
                     redis.call('LREM', @errorkey, -1, @uuid) 
                     redis.call('zrem', @delaykey, @uuid) 
                     redis.call('zrem', @expirekey, @uuid) 
                     redis.call('hdel', @StatusKey, @uuid) 

                     local jobName = redis.call('hget', @JobIDKey, @uuid) 
                     if (jobName) then
                        redis.call('hdel', @JobIDKey, @uuid) 
                        redis.call('hdel', @JobKey, jobName) 
                     end
                     return 1";
        }
Exemplo n.º 53
0
        public EnqueueLua(IRedisConnection connection, RedisNames redisNames)
            : base(connection, redisNames)
        {
            Script = @"local signal = tonumber(@signalID)
                       local id = @field
                    
                    if @JobName ~= '' then
                        local jobExists = redis.call('hget', @JobKey, @JobName) 
                        if(jobExists) then
                            return 'JobAlreadyExists'
                        end
                        local alreadyScheduledAndRan = redis.call('hget', @JobEventKey, @JobNameScheduled)
                        if (alreadyScheduledAndRan == @ScheduledTime) then
                            return 'JobAlreadyExists'
                        end
                    end

                     if id == '' then
                        id = redis.call('INCR', @IDKey)
                     end

                     redis.call('hset', @key, id, @value) 
                     redis.call('hset', @headerskey, id, @headers) 
                     redis.call('lpush', @pendingkey, id) 
                     redis.call('hset', @metakey, id, @metavalue) 
                     redis.call('hset', @StatusKey, id, '0')
                     if @JobName ~= '' then
                        redis.call('hset', @JobKey, @JobName, id)
                        redis.call('hset', @JobIDKey, id, @JobName)

                        redis.call('hset', @JobEventKey, @JobName, @EventTime)
                        redis.call('hset', @JobEventKey, @JobNameScheduled, @ScheduledTime)
                     end
                     if signal == 1 then
                        redis.call('publish', @channel, id) 
                     else
                        redis.call('publish', @channel, '') 
                     end
                     return id";
        }
        public MoveDelayedToPendingLua(IRedisConnection connection, RedisNames redisNames)
            : base(connection, redisNames)
        {
            Script = @"local signal = tonumber(@signalID)
                       local uuids = redis.call('zrangebyscore', @delaykey, 0, @currenttime, 'LIMIT', 0, @limit)
                       if #uuids == 0 then
                        return 0
                       end

                       for k, v in pairs(uuids) do                             
                        redis.call('zrem',  @delaykey, v)
                        redis.call('lpush', @pendingkey, v) 
                        if signal == 1 then
                            redis.call('publish', @channel, v) 
                        end
                       end

                        if signal == 0 then
                            redis.call('publish', @channel, '') 
                        end
                      return table.getn(uuids)";
        }
Exemplo n.º 55
0
        public ResetHeartbeatLua(IRedisConnection connection, RedisNames redisNames)
            : base(connection, redisNames)
        {
            Script = @"local signal = tonumber(@signalID)
                        local uuids = redis.call('zrangebyscore', @workingkey, 0, @heartbeattime, 'LIMIT', 0, @limit)
                        if #uuids == 0 then
	                        return 0
                        end
                        for k, v in pairs(uuids) do                             
	                        redis.call('zrem',  @workingkey, v)
	                        redis.call('rpush', @pendingkey, v) 
                            redis.call('hset', @StatusKey, v, '0') 
	                        if signal == 1 then
		                        redis.call('publish', @channel, v) 
	                        end
                        end

                        if signal == 0 then
	                        redis.call('publish', @channel, '') 
                        end
                        return table.getn(uuids)";
        }
Exemplo n.º 56
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EnqueueExpirationLua"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        public EnqueueExpirationLua(IRedisConnection connection, RedisNames redisNames)
            : base(connection, redisNames)
        {
            Script = @"local id = @field
                    
                     if id == '' then
                        id = redis.call('INCR', @IDKey)
                     end

                     local signal = tonumber(@signalID)
                     redis.call('hset', @key, id, @value) 
                     redis.call('hset', @headerskey, id, @headers) 
                     redis.call('lpush', @pendingkey, id) 
                     redis.call('zadd', @expirekey, @timestampexpire, id) 
                     redis.call('hset', @metakey, id, @metavalue) 
                     redis.call('hset', @StatusKey, id, '0') 
                      if signal == 1 then
                        redis.call('publish', @channel, id) 
                     else
                        redis.call('publish', @channel, '') 
                     end
                     return id";
        }
Exemplo n.º 57
0
 public IRedisPipeline CreateRedisPipeline(IRedisConnection connection, bool transactioned)
 {
     return this.createRedisPipeline(connection, transactioned);
 }
Exemplo n.º 58
0
 private bool AuthIfHasPwd(IRedisConnection cont)
 {
     if (!string.IsNullOrWhiteSpace(cont.Password))
     {
         var authInfo = cont.Execute(new RedisCommand(Command.AUTH, cont.Password)).Read<string>(Readers.ReadAsString);
         if (!RedisUtil.IsOK(authInfo))
         {
             Show(authInfo);
             return false;
         }
     }
     return true;
 }
Exemplo n.º 59
0
 public RedisMessageBus(IDependencyResolver resolver, RedisScaleoutConfiguration configuration, IRedisConnection connection)
     : this(resolver, configuration, connection, true)
 {
 }
Exemplo n.º 60
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SendHeartbeatLua"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="redisNames">The redis names.</param>
 public SendHeartbeatLua(IRedisConnection connection, RedisNames redisNames)
     : base(connection, redisNames)
 {
     Script = @"redis.call('zadd', @workingkey, 'XX', @timestamp, @uuid) ";
 }