/// <summary>
 /// 初始化一个<see cref="RedisSubscription"/>类型的实例
 /// </summary>
 /// <param name="storage">Redis存储</param>
 /// <param name="redisClient">Redis客户端</param>
 public RedisSubscription(RedisStorage storage, CSRedisClient redisClient)
 {
     _storage         = storage ?? throw new ArgumentNullException(nameof(storage));
     _redisClient     = redisClient ?? throw new ArgumentNullException(nameof(redisClient));
     Channel          = _storage.GetRedisKey("JobFetchChannel");
     _subscribeObject = _redisClient.Subscribe((Channel, r => _mre.Set()));
 }
        /// <summary>
        /// Tells the bootstrapper to use Redis as a job storage
        /// available at localhost:6379 and use the '0' db to store 
        /// the data.
        /// </summary>
        public static RedisStorage UseRedisStorage(
            this IBootstrapperConfiguration configuration)
        {
            var storage = new RedisStorage();
			GlobalConfiguration.Configuration.UseStorage(storage);
            return storage;
        }
        public RedisFetchedJob(
            [NotNull] RedisStorage storage,
            [NotNull] IDatabase redis,
            [NotNull] string jobId,
            [NotNull] string queue)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (redis == null)
            {
                throw new ArgumentNullException(nameof(redis));
            }
            if (jobId == null)
            {
                throw new ArgumentNullException(nameof(jobId));
            }
            if (queue == null)
            {
                throw new ArgumentNullException(nameof(queue));
            }

            _storage = storage;
            _redis   = redis;

            JobId = jobId;
            Queue = queue;
        }
Ejemplo n.º 4
0
        public RedisConnection(
            [NotNull] RedisStorage storage,
            [NotNull] IDatabase redis,
            [NotNull] RedisSubscription subscription,
            [NotNull] string jobStorageIdentity,
            TimeSpan fetchTimeout)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (redis == null)
            {
                throw new ArgumentNullException(nameof(redis));
            }
            if (subscription == null)
            {
                throw new ArgumentNullException(nameof(subscription));
            }
            if (jobStorageIdentity == null)
            {
                throw new ArgumentNullException(nameof(jobStorageIdentity));
            }

            _storage            = storage;
            _subscription       = subscription;
            _jobStorageIdentity = jobStorageIdentity;
            _fetchTimeout       = fetchTimeout;

            Redis = redis;
        }
Ejemplo n.º 5
0
        public RedisFetchedJob(
            [NotNull] RedisStorage storage,
            [NotNull] CSRedis.CSRedisClient redisClient,
            [NotNull] string jobId,
            [NotNull] string queue)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (redisClient == null)
            {
                throw new ArgumentNullException(nameof(redisClient));
            }
            if (jobId == null)
            {
                throw new ArgumentNullException(nameof(jobId));
            }
            if (queue == null)
            {
                throw new ArgumentNullException(nameof(queue));
            }

            _storage     = storage;
            _redisClient = redisClient;
            JobId        = jobId;
            Queue        = queue;
        }
Ejemplo n.º 6
0
        public RedisSubscription([NotNull] RedisStorage storage, [NotNull] ISubscriber subscriber)
        {
            _storage = storage ?? throw new ArgumentNullException(nameof(storage));
            Channel  = _storage.GetRedisKey("JobFetchChannel");

            _subscriber = subscriber ?? throw new ArgumentNullException(nameof(subscriber));
            _subscriber.Subscribe(Channel, (channel, value) => _mre.Set());
        }
        /// <summary>
        /// Tells the bootstrapper to use Redis as a job storage
        /// available at the specified host and port and store the
        /// data in db with number '0'.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        /// <param name="hostAndPort">Host and port, for example 'localhost:6379'</param>
        public static RedisStorage UseRedisStorage(
            this IBootstrapperConfiguration configuration,
            string hostAndPort)
        {
            var storage = new RedisStorage(hostAndPort);
            GlobalConfiguration.Configuration.UseStorage(storage);

            return storage;
        }
        /// <summary>
        /// Tells the bootstrapper to use Redis as a job storage
        /// available at localhost:6379 and use the '0' db to store
        /// the data.
        /// </summary>
        public static RedisStorage UseRedisStorage(
            this IBootstrapperConfiguration configuration)
        {
            var storage = new RedisStorage();

            configuration.UseStorage(storage);

            return(storage);
        }
Ejemplo n.º 9
0
        public override void RemoveHash(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            _transaction.KeyDeleteAsync(RedisStorage.GetRedisKey(key));
        }
Ejemplo n.º 10
0
        public void RemoveHash(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            _transaction.QueueCommand(x => x.Remove(RedisStorage.GetRedisKey(key)));
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 初始化一个<see cref="ExpiredJobsWatcher"/>类型的实例
 /// </summary>
 /// <param name="storage">Redis存储</param>
 /// <param name="checkInterval">检查间隔</param>
 public ExpiredJobsWatcher(RedisStorage storage, TimeSpan checkInterval)
 {
     if (checkInterval.Ticks <= 0)
     {
         throw new ArgumentOutOfRangeException(nameof(checkInterval), "Check interval should be positive.");
     }
     _storage       = storage ?? throw new ArgumentNullException(nameof(storage));
     _checkInterval = checkInterval;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 初始化一个<see cref="FetchedJobsWatcher"/>类型的实例
 /// </summary>
 /// <param name="storage">Redis存储</param>
 /// <param name="invisibilityTimeout">隐形超时时间</param>
 /// <param name="options">拉取作业观察者选项配置</param>
 public FetchedJobsWatcher(RedisStorage storage, TimeSpan invisibilityTimeout, FetchedJobsWatcherOptions options)
 {
     if (invisibilityTimeout.Ticks <= 0)
     {
         throw new ArgumentOutOfRangeException(nameof(invisibilityTimeout), "Invisibility timeout duration should be positive.");
     }
     _storage             = storage ?? throw new ArgumentNullException(nameof(storage));
     _options             = options ?? throw new ArgumentNullException(nameof(options));
     _invisibilityTimeout = invisibilityTimeout;
 }
 /// <summary>
 /// 初始化一个<see cref="RedisConnection"/>类型的实例
 /// </summary>
 /// <param name="storage">Redis存储</param>
 /// <param name="redisClient">Redis客户端</param>
 /// <param name="subscription">Redis订阅</param>
 /// <param name="fetchTimeout">拉取超时时间</param>
 public RedisConnection([NotNull] RedisStorage storage
                        , CSRedisClient redisClient
                        , [NotNull] RedisSubscription subscription
                        , TimeSpan fetchTimeout)
 {
     _storage      = storage ?? throw new ArgumentNullException(nameof(storage));
     _subscription = subscription ?? throw new ArgumentNullException(nameof(subscription));
     _fetchTimeout = fetchTimeout;
     RedisClient   = redisClient;
 }
        public RedisWriteOnlyTransaction([NotNull] RedisStorage storage)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }

            _storage        = storage;
            redisClientPipe = _storage.RedisClient.StartPipe();
        }
 /// <summary>
 /// 初始化一个<see cref="RedisFetchedJob"/>类型的实例
 /// </summary>
 /// <param name="storage">Redis存储</param>
 /// <param name="redisClient">Redis客户端</param>
 /// <param name="jobId">作业标识</param>
 /// <param name="queue">队列</param>
 public RedisFetchedJob([NotNull] RedisStorage storage
                        , [NotNull] CSRedisClient redisClient
                        , [NotNull] string jobId
                        , [NotNull] string queue)
 {
     _storage     = storage ?? throw new ArgumentNullException(nameof(storage));
     _redisClient = redisClient ?? throw new ArgumentNullException(nameof(redisClient));
     JobId        = jobId ?? throw new ArgumentNullException(nameof(jobId));
     Queue        = queue ?? throw new ArgumentNullException(nameof(queue));
 }
        /// <summary>
        /// Tells the bootstrapper to use Redis as a job storage
        /// available at the specified host and port and store the
        /// data in db with number '0'.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        /// <param name="hostAndPort">Host and port, for example 'localhost:6379'</param>
        public static RedisStorage UseRedisStorage(
            this IBootstrapperConfiguration configuration,
            string hostAndPort)
        {
            var storage = new RedisStorage(hostAndPort);

            configuration.UseStorage(storage);

            return(storage);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 启用基于CSRedisCore实现的Redis存储
        /// </summary>
        /// <param name="configuration">Hangfire全局配置</param>
        public static IGlobalConfiguration <RedisStorage> UseRedisStorage([NotNull] this IGlobalConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            var storage = new RedisStorage();

            return(configuration.UseStorage(storage));
        }
Ejemplo n.º 18
0
        public HashSet <string> GetAllItemsFromSet(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var result = Redis.GetAllItemsFromSortedSet(RedisStorage.GetRedisKey(key));

            return(new HashSet <string>(result));
        }
Ejemplo n.º 19
0
        public override Dictionary <string, string> GetAllEntriesFromHash(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var result = Redis.HashGetAll(RedisStorage.GetRedisKey(key)).ToStringDictionary();

            return(result.Count != 0 ? result : null);
        }
Ejemplo n.º 20
0
        public RedisConnection(
            [NotNull] RedisStorage storage,
            [NotNull] IDatabase redis,
            [NotNull] RedisSubscription subscription,
            TimeSpan fetchTimeout)
        {
            _storage      = storage ?? throw new ArgumentNullException(nameof(storage));
            _subscription = subscription ?? throw new ArgumentNullException(nameof(subscription));
            _fetchTimeout = fetchTimeout;

            Redis = redis ?? throw new ArgumentNullException(nameof(redis));
        }
        /// <summary>
        /// Tells the bootstrapper to use Redis as a job storage with
        /// the given options, available at the specified host and port,
        /// and store the data in the given database number.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        /// <param name="hostAndPort">Host and port, for example 'localhost:6379'</param>
        /// <param name="db">Database number to store the data, for example '0'</param>
        /// <param name="options">Advanced storage options</param>
        public static RedisStorage UseRedisStorage(
            this IBootstrapperConfiguration configuration,
            string connectionString,
            int db,
            TimeSpan invisibilityTimeout)
        {
            var storage = new RedisStorage(connectionString, db, invisibilityTimeout);

            configuration.UseStorage(storage);

            return(storage);
        }
Ejemplo n.º 22
0
        public override void SetRangeInHash(string key, IEnumerable <KeyValuePair <string, string> > keyValuePairs)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (keyValuePairs == null)
            {
                throw new ArgumentNullException("keyValuePairs");
            }

            Redis.HashSet(RedisStorage.GetRedisKey(key), keyValuePairs.ToHashEntries());
        }
Ejemplo n.º 23
0
        public RedisWriteOnlyTransaction([NotNull] RedisStorage storage, [NotNull] ITransaction transaction)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            _storage     = storage;
            _transaction = transaction;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 启用基于CSRedisCore实现的Redis存储
        /// </summary>
        /// <param name="configuration">Hangfire全局配置</param>
        /// <param name="nameOrConnectionString">连接字符串</param>
        /// <param name="options">Redis存储选项配置</param>
        public static IGlobalConfiguration <RedisStorage> UseRedisStorage([NotNull] this IGlobalConfiguration configuration, [NotNull] string nameOrConnectionString, RedisStorageOptions options = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (nameOrConnectionString == null)
            {
                throw new ArgumentNullException(nameof(nameOrConnectionString));
            }
            var storage = new RedisStorage(nameOrConnectionString, options);

            return(configuration.UseStorage(storage));
        }
Ejemplo n.º 25
0
        public RedisMonitoringApi([NotNull] RedisStorage storage, [NotNull] CSRedisClient redisClient)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (_redisClient == null)
            {
                throw new ArgumentNullException(nameof(redisClient));
            }

            _storage     = storage;
            _redisClient = redisClient;
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 启用基于CSRedisCore实现的Redis存储
        /// </summary>
        /// <param name="configuration">Hangfire全局配置</param>
        /// <param name="redisClient">CSRedisCore客户端</param>
        /// <param name="options">Redis存储选项配置</param>
        public static IGlobalConfiguration <RedisStorage> UseRedisStorage([NotNull] this IGlobalConfiguration configuration, [NotNull] CSRedisClient redisClient, RedisStorageOptions options = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (redisClient == null)
            {
                throw new ArgumentNullException(nameof(redisClient));
            }
            var storage = new RedisStorage(redisClient, options);

            return(configuration.UseStorage(storage));
        }
        public RedisWriteDirectlyToDatabase([NotNull] RedisStorage storage, [NotNull] IDatabase database)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }

            _storage  = storage;
            _database = database;
        }
Ejemplo n.º 28
0
        public RedisMonitoringApi([NotNull] RedisStorage storage, [NotNull] IDatabase database)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }

            _storage  = storage;
            _database = database;
        }
Ejemplo n.º 29
0
        public void SetRangeInHash(
            string key, IEnumerable <KeyValuePair <string, string> > keyValuePairs)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (keyValuePairs == null)
            {
                throw new ArgumentNullException("keyValuePairs");
            }

            _transaction.QueueCommand(
                x => x.SetRangeInHash(RedisStorage.GetRedisKey(key), keyValuePairs));
        }
Ejemplo n.º 30
0
        public override HashSet <string> GetAllItemsFromSet(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            HashSet <string> result = new HashSet <string>();

            foreach (var item in Redis.SortedSetScan(RedisStorage.GetRedisKey(key)))
            {
                result.Add(item.Element);
            }

            return(result);
        }
        public FetchedJobsWatcher(
            RedisStorage storage,
            TimeSpan invisibilityTimeout,
            FetchedJobsWatcherOptions options)
        {
            if (storage == null) throw new ArgumentNullException("storage");
            if (options == null) throw new ArgumentNullException("options");
            if (invisibilityTimeout.Ticks <= 0)
            {
                throw new ArgumentOutOfRangeException("invisibilityTimeout", "Invisibility timeout duration should be positive.");
            }

            _storage = storage;
            _invisibilityTimeout = invisibilityTimeout;
            _options = options;
        }
        public RedisFetchedJob(
            [NotNull] RedisStorage storage,
            [NotNull] IDatabase redis,
            [NotNull] string jobId,
            [NotNull] string queue)
        {
            _storage = storage ?? throw new ArgumentNullException(nameof(storage));
            _redis   = redis ?? throw new ArgumentNullException(nameof(redis));

            JobId = jobId ?? throw new ArgumentNullException(nameof(jobId));
            Queue = queue ?? throw new ArgumentNullException(nameof(queue));

            var halfLife = (int)(storage.InvisibilityTimeout.TotalMilliseconds / 2);

            _timer = new Timer(JobPing, null, halfLife, halfLife);
        }
Ejemplo n.º 33
0
        public FetchedJobsWatcher(
            RedisStorage storage,
            TimeSpan invisibilityTimeout,
            FetchedJobsWatcherOptions options)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (invisibilityTimeout.Ticks <= 0)
            {
                throw new ArgumentOutOfRangeException("invisibilityTimeout", "Invisibility timeout duration should be positive.");
            }

            _storage             = storage;
            _invisibilityTimeout = invisibilityTimeout;
            _options             = options;
        }
        /// <summary>
        /// Tells the bootstrapper to use Redis as a job storage with
        /// the given options, available at the specified host and port,
        /// and store the data in the given database number. 
        /// </summary>
        /// <param name="configuration">Configuration</param>
        /// <param name="hostAndPort">Host and port, for example 'localhost:6379'</param>
        /// <param name="db">Database number to store the data, for example '0'</param>
        /// <param name="options">Advanced storage options</param>
        public static RedisStorage UseRedisStorage(
            this IBootstrapperConfiguration configuration,
            string connectionString,
            int db,
            TimeSpan invisibilityTimeout)
        {
			var storage = new RedisStorage(connectionString, db, invisibilityTimeout);
			GlobalConfiguration.Configuration.UseStorage(storage);

            return storage;
        }
 public FetchedJobsWatcher(RedisStorage storage, TimeSpan invisibilityTimeout)
     : this(storage, invisibilityTimeout, new FetchedJobsWatcherOptions())
 {
 }