コード例 #1
0
 public RedisValue ReceivePublishedMessage(IRedisNode node)
 {
     using (var socket = node.Acquire())
     {
         return socket.ExpectMultiBulkReply();
     }
 }
コード例 #2
0
 public RedisCommandQueue(IRedisNode node, bool transactional)
 {
     _transactional = transactional;
     _node = node;
     _sendQueue = new Queue<RedisCommand>();
     _receiveQueue = new Queue<RedisCommand>();
     _commandBuffer = new CommandBuffer();
 }
コード例 #3
0
        private Dictionary<String,RedisValue> GetInfo(IRedisNode node)
        {
            String info = ExecValue(node, new InfoCommand());
            string[] data = info.Split(new string[]{"\r\n"}, StringSplitOptions.RemoveEmptyEntries);

            var infos = new Dictionary<string, RedisValue>();
            foreach (var item in data)
            {
                var spec = item.Split(':');
                infos.Add(spec[0], spec[1]);
            }
            return infos;
        }
コード例 #4
0
 public bool Ping(IRedisNode node)
 {
     if (!node.Ping())
         return false;
     try
     {
         string status = ExecValue(node, new PingCommand());
         return status == "pong";
     } 
     catch(RedisException)
     {
         return false;    
     }
 }
コード例 #5
0
        void IRedisNodeLocator.Initialize(IList<IRedisNode> nodes)
        {
            if (_isInitialized)
                throw new InvalidOperationException("Instance is already initialized.");

            // locking on this is rude but easy
            lock (_initLock)
            {
                if (_isInitialized)
                    throw new InvalidOperationException("Instance is already initialized.");

                if (nodes.Count > 0)
                    _node = nodes[0];

                _isInitialized = true;
            }
        }
コード例 #6
0
 public RedisValue UnSubscribe(IRedisNode node, params string[] fromChannels)
 {
     return ExecValue(node, new UnsubscribeCommand(fromChannels));
 }
コード例 #7
0
ファイル: ServerPool.cs プロジェクト: vebin/Guanima.Redis
		/// <summary>
		/// Marks a node as dead (unusable)
		///  - moves the node to the  "dead list"
		///  - recreates the locator based on the new list of still functioning servers
		/// </summary>
		/// <param name="node"></param>
		private void MarkAsDead(IRedisNode node)
		{
			_serverAccessLock.UpgradeToWriterLock(Timeout.Infinite);

			try
			{
				// server gained AoeREZ while AFK?
				if (!node.IsAlive)
				{
					_workingServers.Remove(node);
					_deadServers.Add(node);

					RebuildIndexes();
				}
			}
			finally
			{
				_serverAccessLock.ReleaseLock();
			}
		}
コード例 #8
0
 public int Publish(IRedisNode node, string toChannel, RedisValue message)
 {
     return ExecuteInt(node, new PublishCommand(toChannel, message));   
 }
コード例 #9
0
 public SubscriptionState(IRedisNode node)
 {
     _node = node;
     NoMoreSubscriptions = new ManualResetEvent(false);
     SendDone = new ManualResetEvent(false);
 }
コード例 #10
0
 public SubscriptionState GetSubscriptionState(IRedisNode node)
 {
     lock(_lockObject)
     {
         SubscriptionState result;
         if (!_states.TryGetValue(node, out result))
         {
             result = new SubscriptionState(node) {Subscription = this};
             _states.Add(node, result);
         }
         return result;
     }    
 }
コード例 #11
0
ファイル: RedisClient.cs プロジェクト: vebin/Guanima.Redis
        private RedisValue ExecValue(IRedisNode node, RedisCommand command)
        {
            EnqueueCommand(node, command);
            
            if (Pipelining || InTransaction)
                return RedisValue.Empty;

            try
            {
                return command.Value;
            }
            catch (Exception e)
            {
                // TODO generic catch-all does not seem to be a good idea now. Some errors (like command not supported by server) should be exposed 
                // while retaining the fire-and-forget behavior
                HandleException(e);
                throw;
            }
        }
コード例 #12
0
 public RedisValue PUnSubscribe(IRedisNode node, params string[] fromChannelsMatchingPatterns)
 {
     return ExecValue(node, new PUnsubscribeCommand(fromChannelsMatchingPatterns));
 }
コード例 #13
0
 public int DBSize(IRedisNode node)
 {
     return ExecuteInt(node, new DBSizeCommand());
 }
コード例 #14
0
        internal RedisCommandQueue GetCommandQueue(IRedisNode node)
        {
            EnsureCommandQueue();
			RedisCommandQueue q;
			if (!_commandQueues.TryGetValue(node, out q)) {
				q = new RedisCommandQueue(node, InTransaction);
			    q.CurrentDB = this.CurrentDB;
				_commandQueues[node] = q;
			}
            else
            {
                q.IsTransactional = InTransaction;
            }
            return q;
        }
コード例 #15
0
        public void EnqueueCommand(IRedisNode node, RedisCommand command)
        {
			RedisCommandQueue q = GetCommandQueue(node);
 			q.Enqueue(command);
            // if (Pipelined || InTransaction)
             _queuedCommandList.Add(command);
        }
コード例 #16
0
ファイル: RedisClient.cs プロジェクト: vebin/Guanima.Redis
 protected bool ExecuteBool(IRedisNode node, RedisCommand command)
 {
     return ExecuteInt(node, command) > 0;
 }
コード例 #17
0
ファイル: RedisClient.cs プロジェクト: vebin/Guanima.Redis
 protected long ExecuteLong(IRedisNode node, RedisCommand command)
 {
     var val = ExecValue(node, command);
     if (Pipelining)
         return 0;
     return val;
 }
コード例 #18
0
ファイル: RedisClient.cs プロジェクト: vebin/Guanima.Redis
 protected int ExecuteInt(IRedisNode node, RedisCommand command)
 {
     var val = ExecValue(node, command);
     return Pipelining ? 0 : (int) val;
 }
コード例 #19
0
 public RedisValue PSubscribe(IRedisNode node, IEnumerable<String> toChannelsMatchingPatterns)
 {
     if (toChannelsMatchingPatterns.Count() == 0)
         throw new ArgumentNullException("toChannelsMatchingPatterns");
     return ExecValue(node, new PSubscribeCommand(toChannelsMatchingPatterns));
 }
コード例 #20
0
 public RedisValue PSubscribe(IRedisNode node, params string[] toChannelsMatchingPatterns)
 {
     if (toChannelsMatchingPatterns.Length == 0)
         throw new ArgumentNullException("toChannelsMatchingPatterns");
     return ExecValue(node, new PSubscribeCommand(toChannelsMatchingPatterns));
 }
コード例 #21
0
 public RedisCommandQueue(IRedisNode node)
     :this(node, false)
 {
 }
コード例 #22
0
 public RedisClient FlushAll(IRedisNode node)
 {
     Execute(node, new FlushAllCommand());
     return this;
 }
コード例 #23
0
ファイル: RedisClient.cs プロジェクト: vebin/Guanima.Redis
        public IDisposable On(IRedisNode node)
        {
            if (node == null)
                throw new ArgumentNullException("node");
            if (!node.IsAlive)
                throw new RedisClientException("The node is not responding : " + node.Alias);
            if (_onNodeStack == null)
                _onNodeStack = new Stack<IRedisNode>();

            _onNodeStack.Push(node);
            return new DisposableAction(() =>
                                            {
                                                _onNodeStack.Pop();
                                                if (_onNodeStack.Count == 0)
                                                    _onNodeStack = null;
                                            });
        }
コード例 #24
0
 public RedisValue Echo(IRedisNode node, RedisValue value)
 {
     return ExecValue(node, new EchoCommand(value));    
 }
コード例 #25
0
 public void Auth(IRedisNode node, string password)
 {
     Execute(node, new AuthCommand(password));
 }
コード例 #26
0
 public void Quit(IRedisNode node)
 {
     Execute(node, new QuitCommand());
 }
コード例 #27
0
        private static List<uint> GenerateKeys(IRedisNode node, int numberOfKeys)
        {
            const int keyLength = 4;
            const int partCount = 1; // (ModifiedFNV.HashSize / 8) / KeyLength; // HashSize is in bits, uint is 4 byte long

            //if (partCount < 1)
            //    throw new ArgumentOutOfRangeException("The hash algorithm must provide at least 32 bits long hashes");

            var k = new List<uint>(partCount * numberOfKeys);

            // every server is registered numberOfKeys times
            // using UInt32s generated from the different parts of the hash
            // i.e. hash is 64 bit:
            // 00 00 aa bb 00 00 cc dd
            // server will be stored with keys 0x0000aabb & 0x0000ccdd
            // (or a bit differently based on the little/big indianness of the host)
            string address = node.EndPoint.ToString();

            for (int i = 0; i < numberOfKeys; i++)
            {
                byte[] data = new FNV1a().ComputeHash(Encoding.ASCII.GetBytes(String.Concat(address, "-", i)));

                for (int h = 0; h < partCount; h++)
                {
                    k.Add(BitConverter.ToUInt32(data, h * keyLength));
                }
            }

            return k;
        }