public Task <bool> AuthAsync(string password)
        {
            var bytes = Encoding.UTF8.GetBytes($"AUTH {password}\r\n");
            var task  = CreateTask(null, TaskCreationOptions.RunContinuationsAsynchronously);

            LockSend();
            _taskBuffer.Append(task);
            _sender.WriteAsync(bytes);
            ReleaseSend();
            return(task);
        }
        public override Task <bool> SetAsync(string key, string value)
        {
            var      bytes = Encoding.UTF8.GetBytes($"*3\r\n$3\r\nSET\r\n${key.Length}\r\n{key}\r\n${value.Length}\r\n{value}\r\n");
            var      task  = CreateTask(null, TaskCreationOptions.RunContinuationsAsynchronously);
            SpinWait wait  = default;

            if (!TryGetSendLock())
            {
                wait.SpinOnce();
                if (!TryGetSendLock())
                {
                    if (bytes.Length + _memeory.Position < BackupBufferLength)
                    {
                        _memeory.Write(bytes);
                        _tempBuffer.Append(task);
                    }
                    return(task);
                }
            }
            if (_memeory.Position > 0)
            {
                var array = _memeory.GetBuffer().AsSpan().Slice(0, (int)_memeory.Position).ToArray();
                _sender.WriteAsync(new ReadOnlyMemory <byte>(array));
                _memeory.Position = 0;
            }
            _taskBuffer.Append(task);
            _sender.WriteAsync(bytes);


            ReleaseSend();
            return(task);
        }
Beispiel #3
0
 private void GetTaskSpan()
 {
     LockSend();
     if (_currentTaskBuffer.Head.Next != null)
     {
         _taskBuffer.Append(_currentTaskBuffer);
         _currentTaskBuffer = new SingleLinks2 <bool>();
     }
     ReleaseSend();
 }