private Queue <String> LoadUnexistentScripts(SocketReader reader, SocketWriter writer)
        {
            var loadQueue = new Queue <String>();

            // read results
            var result = RESPObject.Read(reader);
            var array  = result.Cast <RESPArray>();

            // if a script does not exists, send 'script load'
            for (int i = 0; i < array.Count; i++)
            {
                var found = array[i].Cast <RESPInteger>().Value != 0;
                if (!found)
                {
                    var digest = _procedures.Digests[i];
                    _logger.Info("Script with digest {0} not found, loading...", digest);
                    var load = GenerateLoadCommand(digest);
                    load.WriteTo(writer);
                    loadQueue.Enqueue(digest);
                }
            }

            writer.Flush();
            return(loadQueue);
        }
Esempio n. 2
0
        public void Initialize(SocketReader reader, SocketWriter writer)
        {
            if (_commands == null || _commands.Length == 0)
            {
                return;
            }

            SendCommands(writer);

            writer.Flush();

            ReadResults(reader);
        }
Esempio n. 3
0
        public void Initialize(SocketReader reader, SocketWriter writer)
        {
            var currentSubscriptions = _subscriptions.GetAllSubscribeCommands();

            if (currentSubscriptions.Any())
            {
                foreach (var command in currentSubscriptions)
                {
                    command.WriteTo(writer);
                }

                writer.Flush();
            }
        }
        private Boolean ShouldLoadScripts(SocketWriter writer)
        {
            if (_procedures.Digests.Any())
            {
                var array = new RESPCommand(new RESPCommandLiteral("SCRIPT"), false);
                array.Add(new RESPCommandLiteral("exists"));
                foreach (var digest in _procedures.Digests)
                {
                    _logger.Info("Checking existence of script digest {0}...", digest);
                    array.Add(new RESPCommandLiteral(digest));
                }

                array.WriteTo(writer);
                writer.Flush();
                return(true);
            }
            return(false);
        }
Esempio n. 5
0
        private void WriteToken(SocketWriter writer, ExecutionToken token)
        {
            try
            {
                _logger.Debug("{0} Received token {1}.", _code, token);

                var hasCommands = false;

                foreach (var command in ExecuteOperation(token))
                {
                    // some subscription commands are aggregated
                    // and produce no commands.
                    if (!hasCommands)
                    {
                        hasCommands = true;
                        _pending.Enqueue(token);
                    }
                    command.WriteTo(writer);
                }

                if (hasCommands)
                {
                    writer.Flush(); // using the async version kills performance, worth investigating why
                    _logger.Debug("{0} flushed buffer.", _code);
                }
            }
            catch (OperationCanceledException)
            {
                token.SetCancelled();
                throw;
            }
            catch (Exception ex)
            {
                token.SetFaulted(ex);
                throw;
            }
        }