コード例 #1
0
        private async Task <uint?> GetCidAsync(string fullyQualifiedName, bool sendAsBody, bool retryIfFailure)
        {
            using var rootSpan = RootSpan(OuterRequestSpans.ServiceSpan.Internal.GetCid);
            using var getCid   = new GetCid
                  {
                      Opaque = SequenceGenerator.GetNext(),
                      Span   = rootSpan,
                  };

            if (sendAsBody)
            {
                getCid.Content = fullyQualifiedName;
            }
            else
            {
                getCid.Key = fullyQualifiedName;
            }

            var options = new GetOptions();

            _operationConfigurator.Configure(getCid, options.Transcoder(_rawStringTranscoder));
            using var ctp = CreateRetryTimeoutCancellationTokenSource(options, getCid);
            if (retryIfFailure)
            {
                await _bucket.RetryAsync(getCid, ctp.TokenPair).ConfigureAwait(false);
            }
            else
            {
                await _bucket.SendAsync(getCid, ctp.TokenPair).ConfigureAwait(false);
            }

            var resultWithValue = getCid.GetValueAsUint();

            return(resultWithValue);
        }
コード例 #2
0
        public static Task <IGetResult> GetAsync(this ICouchbaseCollection collection, string id, Action <GetOptions> configureOptions)
        {
            var options = new GetOptions();

            configureOptions?.Invoke(options);

            return(collection.GetAsync(id, options));
        }
コード例 #3
0
        public async Task <IGetResult> GetAsync(string id, GetOptions options)
        {
            var specs = new List <OperationSpec>();

            if (options.IncludeExpiry)
            {
                specs.Add(new OperationSpec
                {
                    OpCode    = OpCode.SubGet,
                    Path      = VirtualXttrs.DocExpiryTime,
                    PathFlags = SubdocPathFlags.Xattr
                });
            }
            if (!options.Timeout.HasValue)
            {
                options.Timeout = DefaultTimeout;
            }

            var projectList = options.ProjectList;

            if (projectList.Any())
            {
                //we have succeeded the max #fields returnable by sub-doc so fetch the whole doc
                if (projectList.Count + specs.Count > 16)
                {
                    specs.Add(new OperationSpec
                    {
                        Path     = "",
                        OpCode   = OpCode.Get,
                        DocFlags = SubdocDocFlags.None
                    });
                }
                else
                {
                    //Add the projections for fetching
                    projectList.ForEach(path => specs.Add(new OperationSpec
                    {
                        OpCode = OpCode.SubGet,
                        Path   = path
                    }));
                }
            }
            else
            {
                //Project list is empty so fetch the whole doc
                specs.Add(new OperationSpec
                {
                    Path     = "",
                    OpCode   = OpCode.Get,
                    DocFlags = SubdocDocFlags.None
                });
            }

            var lookupOp = await ExecuteLookupIn(id,
                                                 specs, new LookupInOptions().WithTimeout(options.Timeout.Value))
                           .ConfigureAwait(false);

            var transcoder = options.Transcoder ?? _transcoder;

            return(new GetResult(lookupOp.ExtractData(), transcoder, specs, projectList)
            {
                Id = lookupOp.Key,
                Cas = lookupOp.Cas,
                OpCode = lookupOp.OpCode,
                Flags = lookupOp.Flags,
                Header = lookupOp.Header
            });
        }