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"; }
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(); }); } }
public RedisCachingProvider(string connectionName, IConfig <RedisCachingConfig> config, ILogService logService, IRedisConnection connection) { ConnectionName = connectionName; _config = config; _logService = logService; _connection = connection; }
/// <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(); }); } }
/// <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)"; }
internal RedisClient(RedisEndpoint endpoint, IRedisConnection connection) { this.endpoint = endpoint; this.connection = connection; this.connection.Connecting += OnConnecting; this.connection.Disconnecting += OnDisconnecting; }
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(); }); } }
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); }
/// <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') "; }
public RedisMultiBytes ExpectMultiDataBytes(IRedisConnection connection, bool throwException = true) { using (var response = ExecuteInternal(connection, throwException)) { return(ForMultiDataBytes(response, throwException)); } }
public RedisNullableDouble ExpectNullableDouble(IRedisConnection connection, bool throwException = true) { using (var response = ExecuteInternal(connection, throwException)) { return(ForNullableDouble(response, throwException)); } }
public void Initialize(IRedisConnection <ConnectionMultiplexer> connection) { if (connection != null) { _client = connection.Connect(); } }
public EventBusRedis(IRedisConnection redisConnection, ILifetimeScope lifetimeScope, ILogger <EventBusRedis> logger, IEventBusSubscribeManager eventBusSubscribeManager) { this.redisConnection = redisConnection; this.lifetimeScope = lifetimeScope; this.logger = logger; this.eventBusSubscribeManager = eventBusSubscribeManager; }
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); }
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 })); }
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(); }); } }
public DatabaseItem(IRedisConnection cont, string cntName, string dbName, string dbInfo = "") : base(cont, cntName) { DbName = dbName; DbInfo = dbInfo; DbIndex = DbName.GetNumber().ToInt32(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"; }
/// <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)"; }
/// <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"; }
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; } }
public PipelinedCommandExecutor(IRedisConnection conn) { _conn = conn; _reader = new RedisReader(_conn.Reader); _readThread = new Thread(ReadProcedure); _readThread.Start(); }
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(); }); } }
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"; }
public RedisMessageBus(IStringMinifier stringMinifier, ILoggerFactory loggerFactory, IPerformanceCounterManager performanceCounterManager, IOptions<MessageBusOptions> optionsAccessor, IOptions<RedisScaleoutOptions> scaleoutConfigurationAccessor, IRedisConnection connection) : this(stringMinifier, loggerFactory, performanceCounterManager, optionsAccessor, scaleoutConfigurationAccessor, connection, true) { }
/// <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"; }
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; }
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; }
public RedisRepo( IRedisConnection con, IRedisConfig config, IJsonService json) { _con = con; _config = config; _json = json; }
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); }
/// <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; }
/// <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; }
/// <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; } }
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}"; }
/// <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); }
/// <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"; }
/// <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(); }
/// <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"; }
/// <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"; }
/// <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"; }
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)"; }
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)"; }
/// <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"; }
public IRedisPipeline CreateRedisPipeline(IRedisConnection connection, bool transactioned) { return this.createRedisPipeline(connection, transactioned); }
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; }
public RedisMessageBus(IDependencyResolver resolver, RedisScaleoutConfiguration configuration, IRedisConnection connection) : this(resolver, configuration, connection, true) { }
/// <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) "; }