Beispiel #1
0
        /// <inheritdoc />
        public IEnumerable <ITaskProcessorRuntimeInfo> GetAll()
        {
            IEnumerable <string> entityIds = this.provider.GetSet(RedisTaskProcessorRuntimeInfoRepository.EntitySetKey);

            List <ITaskProcessorRuntimeInfo> result = new List <ITaskProcessorRuntimeInfo>();

            using (IRedisPipeline pipeline = this.provider.CreatePipeline())
            {
                foreach (string entityId in entityIds)
                {
                    string entityKey = RedisTaskProcessorRuntimeInfoRepository.GetEntityKey(entityId);

                    pipeline.GetHash(entityKey, values =>
                    {
                        if (values.Count > 0)
                        {
                            result.Add(RedisTaskProcessorRuntimeInfoRepository.Convert(values));
                        }
                    });
                }

                pipeline.Flush();
            }

            return(result);
        }
Beispiel #2
0
        /// <inheritdoc />
        public void Update(ITaskProcessorRuntimeInfo taskProcessorInfo)
        {
            if (taskProcessorInfo == null)
            {
                throw new ArgumentNullException("taskProcessorInfo");
            }

            Trace.WriteLine("ENTER: Updating {0} ...".FormatInvariant(taskProcessorInfo));

            string entityKey = RedisTaskProcessorRuntimeInfoRepository.GetEntityKey(taskProcessorInfo.TaskProcessorId);

            IReadOnlyDictionary <string, string> values = RedisTaskProcessorRuntimeInfoRepository.Serialize(taskProcessorInfo);

            using (IRedisTransaction transaction = this.provider.CreateTransaction())
            {
                transaction.RemoveKey(entityKey);

                transaction.SetHashValues(entityKey, values);

                if (this.expiration < TimeSpan.MaxValue)
                {
                    transaction.ExpireKeyIn(entityKey, this.expiration);
                }

                transaction.Commit();
            }

            Trace.WriteLine("EXIT: {0} updated.".FormatInvariant(taskProcessorInfo));
        }
Beispiel #3
0
        /// <inheritdoc />
        public ITaskProcessorRuntimeInfo GetById(Guid taskProcessorId)
        {
            string entityKey = RedisTaskProcessorRuntimeInfoRepository.GetEntityKey(taskProcessorId);

            IReadOnlyDictionary <string, string> values = this.provider.GetHashAsText(entityKey);

            if (values.Count == 0)
            {
                return(null);
            }

            return(RedisTaskProcessorRuntimeInfoRepository.Convert(values));
        }
Beispiel #4
0
        /// <inheritdoc />
        public void Delete(Guid taskProcessorId)
        {
            string entityKey = RedisTaskProcessorRuntimeInfoRepository.GetEntityKey(taskProcessorId);

            using (IRedisTransaction transaction = this.provider.CreateTransaction())
            {
                transaction.RemoveFromSet(RedisTaskProcessorRuntimeInfoRepository.EntitySetKey, RedisConverter.ToString(taskProcessorId));

                transaction.RemoveKey(entityKey);

                transaction.Commit();
            }
        }
Beispiel #5
0
        /// <inheritdoc />
        public bool Heartbeat(Guid taskProcessorId)
        {
            Trace.WriteLine("ENTER: Heart-beating {0} ...".FormatInvariant(taskProcessorId));

            string entityKey = RedisTaskProcessorRuntimeInfoRepository.GetEntityKey(taskProcessorId);

            if (this.provider.ExpireKeyIn(entityKey, this.Expiration))
            {
                Trace.WriteLine("EXIT: {0} heartbeat successful.".FormatInvariant(taskProcessorId));

                return(true);
            }
            else
            {
                Trace.WriteLine("EXIT: {0} heartbeat failed.".FormatInvariant(taskProcessorId));

                return(false);
            }
        }
Beispiel #6
0
 private static string GetEntityKey(Guid entityId)
 {
     return(RedisTaskProcessorRuntimeInfoRepository.GetEntityKey(RedisConverter.ToString(entityId)));
 }