public RedisValue ReceivePublishedMessage(IRedisNode node) { using (var socket = node.Acquire()) { return socket.ExpectMultiBulkReply(); } }
public RedisCommandQueue(IRedisNode node, bool transactional) { _transactional = transactional; _node = node; _sendQueue = new Queue<RedisCommand>(); _receiveQueue = new Queue<RedisCommand>(); _commandBuffer = new CommandBuffer(); }
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; }
public bool Ping(IRedisNode node) { if (!node.Ping()) return false; try { string status = ExecValue(node, new PingCommand()); return status == "pong"; } catch(RedisException) { return false; } }
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; } }
public RedisValue UnSubscribe(IRedisNode node, params string[] fromChannels) { return ExecValue(node, new UnsubscribeCommand(fromChannels)); }
/// <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(); } }
public int Publish(IRedisNode node, string toChannel, RedisValue message) { return ExecuteInt(node, new PublishCommand(toChannel, message)); }
public SubscriptionState(IRedisNode node) { _node = node; NoMoreSubscriptions = new ManualResetEvent(false); SendDone = new ManualResetEvent(false); }
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; } }
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; } }
public RedisValue PUnSubscribe(IRedisNode node, params string[] fromChannelsMatchingPatterns) { return ExecValue(node, new PUnsubscribeCommand(fromChannelsMatchingPatterns)); }
public int DBSize(IRedisNode node) { return ExecuteInt(node, new DBSizeCommand()); }
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; }
public void EnqueueCommand(IRedisNode node, RedisCommand command) { RedisCommandQueue q = GetCommandQueue(node); q.Enqueue(command); // if (Pipelined || InTransaction) _queuedCommandList.Add(command); }
protected bool ExecuteBool(IRedisNode node, RedisCommand command) { return ExecuteInt(node, command) > 0; }
protected long ExecuteLong(IRedisNode node, RedisCommand command) { var val = ExecValue(node, command); if (Pipelining) return 0; return val; }
protected int ExecuteInt(IRedisNode node, RedisCommand command) { var val = ExecValue(node, command); return Pipelining ? 0 : (int) val; }
public RedisValue PSubscribe(IRedisNode node, IEnumerable<String> toChannelsMatchingPatterns) { if (toChannelsMatchingPatterns.Count() == 0) throw new ArgumentNullException("toChannelsMatchingPatterns"); return ExecValue(node, new PSubscribeCommand(toChannelsMatchingPatterns)); }
public RedisValue PSubscribe(IRedisNode node, params string[] toChannelsMatchingPatterns) { if (toChannelsMatchingPatterns.Length == 0) throw new ArgumentNullException("toChannelsMatchingPatterns"); return ExecValue(node, new PSubscribeCommand(toChannelsMatchingPatterns)); }
public RedisCommandQueue(IRedisNode node) :this(node, false) { }
public RedisClient FlushAll(IRedisNode node) { Execute(node, new FlushAllCommand()); return this; }
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; }); }
public RedisValue Echo(IRedisNode node, RedisValue value) { return ExecValue(node, new EchoCommand(value)); }
public void Auth(IRedisNode node, string password) { Execute(node, new AuthCommand(password)); }
public void Quit(IRedisNode node) { Execute(node, new QuitCommand()); }
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; }