コード例 #1
0
        public void FingerprintToRedisKey()
        {
            var fp  = Fingerprint.Random();
            var key = _serializer.ToRedisKey(fp);

            Assert.Equal(fp.ToString(), key);
        }
コード例 #2
0
ファイル: RedisMetadataCache.cs プロジェクト: socat/BuildXL
        /// <inheritdoc />
        public async Task <GetContentHashListResult> GetOrAddContentHashListAsync(Context context, StrongFingerprint strongFingerprint, Func <StrongFingerprint, Task <GetContentHashListResult> > getFuncAsync)
        {
            try
            {
                var        cacheKey = _redisSerializer.ToRedisKey(strongFingerprint);
                RedisValue cacheResult;

                Stopwatch stopwatch = Stopwatch.StartNew();
                try
                {
                    _cacheTracer.GetContentHashListStart(context);
                    cacheResult = await StringGetWithExpiryBumpAsync(context, cacheKey);
                }
                finally
                {
                    _cacheTracer.GetContentHashListStop(context, stopwatch.Elapsed);
                }

                if (!cacheResult.HasValue)
                {
                    _cacheTracer.RecordContentHashListFetchedFromBackingStore(context, strongFingerprint);
                    GetContentHashListResult getResult = await getFuncAsync(strongFingerprint);

                    if (getResult.Succeeded)
                    {
                        var cacheValue = _redisSerializer.ToRedisValue(getResult.ContentHashListWithDeterminism);

                        stopwatch = Stopwatch.StartNew();
                        try
                        {
                            _cacheTracer.AddContentHashListStart(context);
                            bool result = await StringSetWithExpiryBumpAsync(context, cacheKey, cacheValue);

                            context.Logger.Debug($"Added redis cache entry for {strongFingerprint}: {getResult}. Result: {result}");
                        }
                        finally
                        {
                            _cacheTracer.AddContentHashListStop(context, stopwatch.Elapsed);
                        }
                    }

                    return(getResult);
                }
                else
                {
                    _cacheTracer.RecordGetContentHashListFetchedDistributed(context, strongFingerprint);
                }

                return(new GetContentHashListResult(_redisSerializer.AsContentHashList(cacheResult)));
            }
            catch (Exception ex)
            {
                return(new GetContentHashListResult(ex));
            }
        }
コード例 #3
0
        public Task TestGetOrAddSelectorsEmptyCache()
        {
            return(RunTest(async(context, metadataCache, redisDb) =>
            {
                var selectors = new[] { Selector.Random(), Selector.Random(), };
                var weakFp = Fingerprint.Random();
                await metadataCache.GetOrAddSelectorsAsync(context, weakFp, fp => ToSelectorResult(selectors)).ShouldBeSuccess();

                // Check Redis data
                Assert.Equal(1, redisDb.DbSet.Keys.Count);

                var cacheKey = _redisSerializer.ToRedisKey(weakFp).Prepend(RedisNameSpace);
                Assert.True(redisDb.DbSet.ContainsKey(cacheKey));
                Assert.Equal(2, redisDb.DbSet[cacheKey].Length);
            }));
        }