Beispiel #1
0
 static Task?BeginSendRemainderInBackground(PooledMultiplexer @this, RespConnection connection,
                                            List <IBatchedOperation> values, CancellationToken cancellationToken)
 {
     return(connection.PreferSync ? Task.Run(() =>
     {
         var len = values.Count;
         try
         {
             for (int i = 1; i < len; i++)
             {
                 Send(@this, connection, values[i], flush: i == len - 1);
             }
         }
         catch (Exception ex)
         {
             connection.Doom();
             Debug.WriteLine(ex.Message);
         }
     }) : Task.Run(async() =>
     {
         var len = values.Count;
         try
         {
             for (int i = 1; i < len; i++)
             {
                 await SendAsync(@this, connection, values[i], cancellationToken, flush: i == len - 1).ConfigureAwait(false);
             }
         }
         catch (Exception ex)
         {
             connection.Doom();
             Debug.WriteLine(ex.Message);
         }
     }));
 }
Beispiel #2
0
 protected PooledBase(PooledMultiplexer muxer, int database)
 {
     Multiplexer = muxer;
     Database    = database;
 }
Beispiel #3
0
            static async PooledValueTask <AsyncLifetime <IDatabase> > Impl(IDatabase db, PooledMultiplexer muxer, CancellationToken cancellationToken)
            {
                var lease = await muxer.RentAsync(cancellationToken).ConfigureAwait(false);

                var leasedDb = new LeasedDatabase(db.Database, muxer, lease, cancellationToken);

                return(new AsyncLifetime <IDatabase>(leasedDb, obj => ((LeasedDatabase)obj).DisposeAsync()));
            }
Beispiel #4
0
 private LeasedDatabase(int db, PooledMultiplexer muxer, AsyncLifetime <RespConnection> lease, CancellationToken cancellationToken)
     : base(muxer, db)
 {
     _lease             = lease;
     _cancellationToken = cancellationToken;
 }
Beispiel #5
0
 public PooledDatabase(PooledMultiplexer parent, int db, in CancellationToken cancellationToken)
Beispiel #6
0
 private static async PooledValueTask SendAsync(PooledMultiplexer @this, RespConnection connection, IBatchedOperation op, CancellationToken cancellationToken, bool flush)
 {
     Interlocked.Increment(ref @this._opCount);
     using var args = op.ConsumeArgs();
     await connection.SendAsync(RespValue.CreateAggregate(RespType.Array, args.Value), cancellationToken, flush).ConfigureAwait(false);
 }
Beispiel #7
0
 static void Send(PooledMultiplexer @this, RespConnection connection, IBatchedOperation op, bool flush)
 {
     Interlocked.Increment(ref @this._opCount);
     using var args = op.ConsumeArgs();
     connection.Send(RespValue.CreateAggregate(RespType.Array, args.Value), flush);
 }