Exemplo n.º 1
0
        public VerifyQueueRecordCount(string queueName, string connectionString)
        {
            var connection = new BaseConnectionInformation(new QueueConnection(queueName, connectionString));

            _redisNames = new RedisNames(connection);
            _connection = new RedisConnection(connection);
        }
Exemplo n.º 2
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') ";
 }
Exemplo n.º 3
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.º 4
0
        public VerifyErrorCounts(string queueName, string connectionString)
        {
            var connection = new BaseConnectionInformation(queueName, connectionString);

            _redisNames = new RedisNames(connection);
            _connection = new RedisConnection(connection);
        }
Exemplo n.º 5
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";
        }
        /// <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)";
        }
        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.º 8
0
        /// <summary>
        /// Gets the parameters.
        /// </summary>
        /// <param name="messageId">The message identifier.</param>
        /// <param name="message">The message.</param>
        /// <param name="headers">The headers.</param>
        /// <param name="metaData">The meta data.</param>
        /// <param name="jobName">Name of the job.</param>
        /// <param name="scheduledTime">The scheduled time.</param>
        /// <param name="eventTime">The event time.</param>
        /// <param name="route">The route.</param>
        /// <returns></returns>
        private object GetParameters(string messageId, byte[] message, byte[] headers, byte[] metaData, string jobName,
                                     DateTimeOffset scheduledTime, DateTimeOffset eventTime, string route)
        {
            var pendingKey = !string.IsNullOrEmpty(route) ? RedisNames.PendingRoute(route) : RedisNames.Pending;
            var realRoute  = string.IsNullOrEmpty(route) ? string.Empty : route;

            return(new
            {
                key = (RedisKey)RedisNames.Values,
                field = messageId,
                value = (RedisValue)message,
                headers,
                headerskey = (RedisKey)RedisNames.Headers,
                pendingkey = (RedisKey)pendingKey,
                channel = RedisNames.Notification,
                metakey = (RedisKey)RedisNames.MetaData,
                metavalue = (RedisValue)metaData,
                Route = realRoute,
                IDKey = (RedisKey)RedisNames.Id,
                JobKey = (RedisKey)RedisNames.JobNames,
                JobIDKey = (RedisKey)RedisNames.JobIdNames,
                JobName = jobName,
                StatusKey = (RedisKey)RedisNames.Status,
                JobEventKey = (RedisKey)RedisNames.JobEvent,
                RouteIDKey = (RedisKey)RedisNames.Route,
                JobNameScheduled = string.Concat(jobName, "|scheduled"),
                ScheduledTime = scheduledTime.ToString(DateTimeScheduler, CultureInfo.InvariantCulture),
                EventTime = eventTime.ToString(DateTimeFormat, CultureInfo.InvariantCulture)
            });
        }
Exemplo n.º 9
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.º 10
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)";
        }
        /// <summary>
        /// Gets the parameters.
        /// </summary>
        /// <param name="messages">The messages.</param>
        /// <param name="route">The route.</param>
        /// <returns></returns>
        private object GetParameters(List <MessageToSend> messages, string route)
        {
            var pendingKey = !string.IsNullOrEmpty(route) ? RedisNames.PendingRoute(route) : RedisNames.Pending;
            // Creates serializer.
            var serializer = SerializationContext.Default.GetSerializer <List <MessageToSend> >();

            using (var output = new MemoryStream())
            {
                serializer.Pack(output, messages, PackerCompatibilityOptions.Classic);
                object rc = new
                {
                    messages   = (RedisValue)output.ToArray(),
                    key        = (RedisKey)RedisNames.Values,
                    pendingkey = (RedisKey)pendingKey,
                    headerskey = (RedisKey)RedisNames.Headers,
                    channel    = RedisNames.Notification,
                    metakey    = (RedisKey)RedisNames.MetaData,
                    IDKey      = (RedisKey)RedisNames.Id,
                    delaykey   = (RedisKey)RedisNames.Delayed,
                    expirekey  = (RedisKey)RedisNames.Expiration,
                    StatusKey  = (RedisKey)RedisNames.Status,
                    RouteIDKey = (RedisKey)RedisNames.Route
                };
                return(rc);
            }
        }
Exemplo n.º 12
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";
        }
        /// <summary>
        /// Gets the parameters.
        /// </summary>
        /// <param name="messageId">The message identifier.</param>
        /// <param name="message">The message.</param>
        /// <param name="headers">The headers.</param>
        /// <param name="metaData">The meta data.</param>
        /// <param name="expireTime">The expire time.</param>
        /// <param name="route">The route.</param>
        /// <returns></returns>
        private object GetParameters(string messageId, byte[] message, byte[] headers, byte[] metaData,
                                     long expireTime, string route)
        {
            var pendingKey = !string.IsNullOrEmpty(route) ? RedisNames.PendingRoute(route) : RedisNames.Pending;
            var realRoute  = string.IsNullOrEmpty(route) ? string.Empty : route;

            return
                (new
            {
                key = (RedisKey)RedisNames.Values,
                field = messageId,
                value = message,
                pendingkey = (RedisKey)pendingKey,
                channel = RedisNames.Notification,
                headers,
                Route = realRoute,
                headerskey = (RedisKey)RedisNames.Headers,
                metakey = (RedisKey)RedisNames.MetaData,
                metavalue = metaData,
                expirekey = (RedisKey)RedisNames.Expiration,
                timestampexpire = expireTime,
                IDKey = (RedisKey)RedisNames.Id,
                StatusKey = (RedisKey)RedisNames.Status,
                RouteIDKey = (RedisKey)RedisNames.Route
            });
        }
Exemplo n.º 14
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.º 15
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";
 }
 /// <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.º 17
0
        public VerifyQueueData(QueueConnection queueConnection, QueueProducerConfiguration configuration)
        {
            _configuration = configuration;
            var connection = new BaseConnectionInformation(queueConnection);

            _redisNames = new RedisNames(connection);
            _connection = new RedisConnection(connection);
        }
Exemplo n.º 18
0
        public VerifyQueueData(string queueName, QueueProducerConfiguration configuration, string connectionString)
        {
            _configuration = configuration;
            var connection = new BaseConnectionInformation(queueName, connectionString);

            _redisNames = new RedisNames(connection);
            _connection = new RedisConnection(connection);
        }
Exemplo n.º 19
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.º 20
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.º 22
0
        public static void SetError(QueueConnection queueConnection, ICreationScope scope)
        {
            var connectionInfo = new BaseConnectionInformation(queueConnection);
            var conn           = new RedisConnection(connectionInfo);
            var redisNames     = new RedisNames(connectionInfo);
            var db             = conn.Connection.GetDatabase();
            var id             = db.HashGet(redisNames.JobNames, "job1");

            db.HashSet(redisNames.Status, id,
                       "2");
        }
Exemplo n.º 23
0
        /// <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.º 24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SaveMetaDataCommandHandler" /> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        /// <param name="internalSerializer">The internal serializer.</param>
        public SaveMetaDataCommandHandler(IRedisConnection connection,
                                          RedisNames redisNames,
                                          IInternalSerializer internalSerializer)
        {
            Guard.NotNull(() => connection, connection);
            Guard.NotNull(() => redisNames, redisNames);
            Guard.NotNull(() => internalSerializer, internalSerializer);

            _redisNames         = redisNames;
            _internalSerializer = internalSerializer;
            _connection         = connection;
        }
        /// <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.º 26
0
        public static void Verify(QueueConnection queueConnection, long messageCount, ICreationScope scope)
        {
            var connectionInfo = new BaseConnectionInformation(queueConnection);
            var redisNames     = new RedisNames(connectionInfo);

            using (var connection = new RedisConnection(connectionInfo))
            {
                var db      = connection.Connection.GetDatabase();
                var records = db.HashLength(redisNames.Values);
                Assert.Equal(messageCount, records);
            }
        }
        /// <summary>Initializes a new instance of the <see cref="DeleteMessageCommandHandler"/> class.</summary>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="connection">Redis connection</param>
        /// <param name="redisNames">Redis key names</param>
        public SendHeartBeatCommandHandler(IUnixTimeFactory unixTimeFactory,
                                           IRedisConnection connection,
                                           RedisNames redisNames)
        {
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);
            Guard.NotNull(() => connection, connection);
            Guard.NotNull(() => redisNames, redisNames);

            _unixTimeFactory = unixTimeFactory;
            _connection      = connection;
            _redisNames      = redisNames;
        }
Exemplo n.º 28
0
 public GetErrorRecordsToDeleteQueryHandler(IRedisConnection connection,
                                            IUnixTimeFactory timeFactory,
                                            IMessageErrorConfiguration errorConfiguration,
                                            RedisNames names,
                                            RedisQueueTransportOptions options)
 {
     _connection         = connection;
     _names              = names;
     _errorConfiguration = errorConfiguration;
     _options            = options;
     _unixTime           = timeFactory;
 }
        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
                                local routeName = redis.call('hget', @RouteIDKey, v) 
                                if(routeName) then
                                   local routePending = @pendingkey .. '_}'.. routeName
                                   inPending = redis.call('LREM', routePending, -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) 
                                       redis.call('hdel', @RouteIDKey, 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
                                else
                                    inProgress = inProgress + 1
                                end
                            end
                        end
                        return table.getn(uuids) - inProgress";
        }
Exemplo n.º 30
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.º 31
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";
 }
Exemplo n.º 32
0
        public void Create_Default()
        {
            var test = new RedisNames(CreateConnection());

            Assert.Contains("testQueue", test.Values);
            Assert.Contains("testQueue", test.Delayed);
            Assert.Contains("testQueue", test.Error);
            Assert.Contains("testQueue", test.Expiration);
            Assert.Contains("testQueue", test.Id);
            Assert.Contains("testQueue", test.MetaData);
            Assert.Contains("testQueue", test.Notification);
            Assert.Contains("testQueue", test.Pending);
            Assert.Contains("testQueue", test.Working);
            Assert.Contains("testQueue", test.Headers);
        }
Exemplo n.º 33
0
        /// <summary>
        /// Gets the parameters.
        /// </summary>
        /// <param name="unixTime">The current unix time.</param>
        /// <param name="route">The route.</param>
        /// <returns></returns>
        private object GetParameters(long unixTime, string route)
        {
            var pendingKey = !string.IsNullOrEmpty(route) ? RedisNames.PendingRoute(route) : RedisNames.Pending;

            return(new
            {
                pendingkey = (RedisKey)pendingKey,
                workingkey = (RedisKey)RedisNames.Working,
                timestamp = unixTime,
                valueskey = (RedisKey)RedisNames.Values,
                headerskey = (RedisKey)RedisNames.Headers,
                expirekey = (RedisKey)RedisNames.Expiration,
                StatusKey = (RedisKey)RedisNames.Status
            });
        }
Exemplo n.º 34
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.º 35
0
 /// <inheritdoc />
 /// <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 = @"redis.call('zrem', @workingkey, @uuid) 
              local routeName = redis.call('hget', @RouteIDKey, @uuid) 
              if(routeName) then
                 local routePending = @pendingkey .. '_}' .. routeName
                 redis.call('rpush', routePending, @uuid) 
              else
                 redis.call('rpush', @pendingkey, @uuid)
              end
              redis.call('hset', @StatusKey, @uuid, '0') 
              redis.call('publish', @channel, '') 
              return 1";
 }
Exemplo n.º 36
0
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new instance of the <see cref="DequeueRpcLua"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="redisNames">The redis names.</param>
 /// <param name="configuration">The configuration.</param>
 public DequeueRpcLua(IRedisConnection connection, RedisNames redisNames, QueueConsumerConfiguration configuration)
     : base(connection, redisNames)
 {
     _configuration = configuration;
     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.º 37
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.º 38
0
 /// <inheritdoc />
 /// <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.º 39
0
        /// <inheritdoc />
        /// <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') 

                     if @Route ~= '' then
                         redis.call('hset', @RouteIDKey, id, @Route)
                     end
                     return id";
        }
Exemplo n.º 40
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.º 41
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.º 42
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";
        }
Exemplo n.º 43
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)";
        }
        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.º 45
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.º 46
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EnqueueBatchLua"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="redisNames">The redis names.</param>
        public EnqueueBatchLua(IRedisConnection connection, RedisNames redisNames)
            : base(connection, redisNames)
        {
            Script = @"local messages = cmsgpack.unpack(@messages)
                        local a={}
                        local i = 1
                        local signal = 0

                        for k1, v1 in pairs(messages) do    
	                        local id
	                        local correlationId
	                        local message
                            local headers
	                        local metadata
	                        local timestamp
	                        local expiretime

	                        for k2, v2 in pairs(v1) do     
		                        local key = tonumber(k2)   
		                        if key == 1 then
			                        correlationId = v2
		                        end 
		                        if key == 2 then
			                        expiretime = tonumber(v2)
		                        end
                                if key == 3 then
			                        headers = v2
		                        end
		                        if key == 4 then
			                        message = v2
		                        end
		                        if key == 5 then
			                        id = v2
		                        end
		                        if key == 6 then
			                        metadata = v2
		                        end
		                        if key == 7 then
			                        timestamp = tonumber(v2)
		                        end
	                        end

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

	                        a[i] = tostring(id)   
	                        a[i+1] = correlationId                         

	                        redis.call('hset', @key, id, message) 
	                        redis.call('hset', @metakey, id, metadata) 
                            redis.call('hset', @headerskey, id, headers) 
                            redis.call('hset', @StatusKey, id, '0') 

	                        if timestamp > 0 then
		                        redis.call('zadd', @delaykey, timestamp, id) 
	                        else
		                        redis.call('lpush', @pendingkey, id) 
		                        signal = 1
	                        end

	                        if expiretime > 0 then
		                        redis.call('zadd', @expirekey, expiretime, id) 
	                        end
	                        i = i + 2
                        end

                        if signal == 1 then
	                        redis.call('publish', @channel, '') 
                        end
                        return cmsgpack.pack(a)";
        }
Exemplo n.º 47
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TimeLua"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="redisNames">The redis names.</param>
 public TimeLua(IRedisConnection connection, RedisNames redisNames)
     : base(connection, redisNames)
 {
     Script = @"return redis.call('time')";
 }
Exemplo n.º 48
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) ";
 }