Exemplo n.º 1
0
 public static ulong GetIndex(string queueName, MemcachedQueueIndexType indexType)
 {
     if (string.IsNullOrWhiteSpace(queueName))
     {
         throw new ArgumentNullException("queueName");
     }
     queueName = queueName.Trim();
     return(GetIndexById(GetQueueId(queueName), indexType));
 }
Exemplo n.º 2
0
 private static string BuildIndexKey(string queueId, MemcachedQueueIndexType indexType)
 {
     if (indexType == MemcachedQueueIndexType.Enqueue)
     {
         return(string.Format("q-idx:{0}-en", queueId));
     }
     else if (indexType == MemcachedQueueIndexType.Dequeue)
     {
         return(string.Format("q-idx:{0}-de", queueId));
     }
     else  // if (indexType == MemcachedQueueIndexType.ClearGarbage)
     {
         return(string.Format("q-idx:{0}-gc", queueId));
     }
 }
Exemplo n.º 3
0
        private static ulong GetIndexById(string queueId, MemcachedQueueIndexType indexType)
        {
            if (string.IsNullOrWhiteSpace(queueId)) // 队列列表里未找到指定名称的队列
            {
                return(0);
            }
            string indexKey     = BuildIndexKey(queueId, indexType);
            var    client       = MemcachedCacheHelper.GetClientInstance();
            string index_string = client.Get(indexKey) as string;
            ulong  index;

            if (string.IsNullOrWhiteSpace(index_string) ||
                index_string == "0" ||
                ulong.TryParse(index_string, out index) == false ||
                index <= 0)
            {
                return(0);
            }
            return(index);
        }