Пример #1
0
        public static async ValueTask <RedisDatabase> CreateDatabaseConnectionAsync(CancellationToken token)
        {
            if (_connectTo == null)
            {
                throw new InvalidOperationException($"{nameof(ConnectionManager)} must be initialized before connecting to a Redis Database");
            }

            Pipe           pipe       = new Pipe();
            ConnectionBase connection = _encryptionKey == Array.Empty <byte>() ?
                                        new PlaintextDataConnection(_hostname, _connectTo, _port, _useSsl, pipe.Writer) :
                                        new EncryptedDataConnection(_hostname, _connectTo, _port, _useSsl, pipe.Writer, _encryptionKey);
            await connection.OpenAsync(token);

            RedisDatabase db = _protocolVersion == 3 ? (RedisDatabase) new V3Database(connection, pipe.Reader) : new V2Database(connection, pipe.Reader);

            if (string.IsNullOrWhiteSpace(_password) == false)
            {
                await db.AuthAsync(_password, token);
            }

            return(db);
        }