예제 #1
0
        public IReadOnlyList <string> GetChildPipeNames(string parentPipeName)
        {
            var db             = _redis.GetDatabase();
            var parentInfoPath = CreateParentChildSetPath(parentPipeName);
            var entries        = db.HashGetAll(parentInfoPath);

            if (entries == null)
            {
                return(new string[0]);
            }

            return(entries.Select(a => RedisExtensions.ReadAsString(a.Name)).ToList());
        }
예제 #2
0
        private bool IsPeerServer(string name)
        {
            string[] buffer = name.Split('!', System.StringSplitOptions.RemoveEmptyEntries);

            if (buffer.Length != 3)
            {
                return(false);
            }

            List <string> peerGameKeys = RedisExtensions.GetAllKeys(RedisDBNumber.PeerGroup);

            if (buffer[2].Length > 2 && peerGameKeys.Contains(buffer[1]))
            {
                return(true);
            }

            return(false);
        }
예제 #3
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            var       streamName = RedisExtensions.GetPrimaryStream();
            IDatabase db         = _connectionMultiplexer.GetDatabase();
            var       batchSize  = _configuration.BatchSize;

            while (true)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }
                var checkpoint = await _checkPoint.GetCheckpoint <T>();

                var streamInfo = db.StreamInfo(streamName);
                if (streamInfo.LastEntry.Id == checkpoint)
                {
                    await Task.Delay(_configuration.Delay, cancellationToken);

                    continue;
                }

                var currentSlice = await db.StreamReadAsync(streamName, checkpoint, batchSize);

                foreach (var streamEntry in currentSlice)
                {
                    foreach (var streamEntryValue in streamEntry.Values)
                    {
                        var @event = JsonConvert.DeserializeObject <AggregateEvent>(streamEntryValue.Value.ToString(), _serializerSettings);
                        await _eventDispatcher.DispatchAsync(@event);

                        await _checkPoint.SetCheckpoint <T>(streamEntry.Id);
                    }
                }
            }
        }
예제 #4
0
 public static bool SetGroupList(string gameName, PeerGroup group)
 {
     return(RedisExtensions.SerializeSet(gameName, group, (int)RedisDBNumber.PeerGroup));
 }
예제 #5
0
 public static PeerGroup GetGroupsList(string gameName)
 {
     return(RedisExtensions.SerilizeGet <PeerGroup>(gameName, (int)RedisDBNumber.PeerGroup));
 }
예제 #6
0
 public static List <string> SearchPeerGroupKeys(string subKey)
 {
     return(RedisExtensions.GetMatchedKeys(subKey, (int)RedisDBNumber.PeerGroup));
 }
예제 #7
0
        public async Task <IActionResult> MarketData(string assetPair)
        {
            var data = await _database.HashGetAllAsync(RedisService.GetMarketDataKey(assetPair));

            var marketSlice = data?.ToMarketSlice() ?? new MarketSlice {
                AssetPairId = assetPair
            };

            var nowDate = DateTime.UtcNow;
            var now     = nowDate.ToUnixTime();
            var from    = (nowDate - _marketDataInterval).ToUnixTime();

            var baseVolumesDataTask  = _database.SortedSetRangeByScoreAsync(RedisService.GetMarketDataBaseVolumeKey(assetPair), from, now);
            var quoteVolumesDataTask = _database.SortedSetRangeByScoreAsync(RedisService.GetMarketDataQuoteVolumeKey(assetPair), from, now);
            var pricesTask           = _database.SortedSetRangeByScoreAsync(RedisService.GetMarketDataPriceKey(assetPair), from, now);

            await Task.WhenAll(baseVolumesDataTask, quoteVolumesDataTask, pricesTask);

            var prices = pricesTask.Result
                         .Where(x => x.HasValue)
                         .Select(x => RedisExtensions.DeserializeWithDate <decimal>(x)).ToList();

            var baseVolumes = baseVolumesDataTask.Result
                              .Where(x => x.HasValue)
                              .Select(x => RedisExtensions.DeserializeWithDate <decimal>(x)).ToList();

            decimal baseVolume = baseVolumes.Sum(x => x.data);

            var quoteVolumes = quoteVolumesDataTask.Result
                               .Where(x => x.HasValue)
                               .Select(x => RedisExtensions.DeserializeWithDate <decimal>(x)).ToList();

            decimal quoteVolume = quoteVolumes.Sum(x => x.data);

            var     pricesList = prices.Select(x => x.data).ToList();
            decimal high       = pricesList.Any() ? pricesList.Max() : 0;
            decimal low        = pricesList.Any() ? pricesList.Min() : 0;

            if (pricesList.Any())
            {
                decimal price = pricesList[0];

                if (price > 0)
                {
                    decimal priceChange = (decimal.Parse(marketSlice.LastPrice, CultureInfo.InvariantCulture) - price) / price;
                    marketSlice.PriceChange = priceChange.ToString(CultureInfo.InvariantCulture);
                }
            }

            if (high > 0)
            {
                marketSlice.High = high.ToString(CultureInfo.InvariantCulture);
            }

            if (low > 0)
            {
                marketSlice.Low = low.ToString(CultureInfo.InvariantCulture);
            }

            marketSlice.VolumeBase  = baseVolume.ToString(CultureInfo.InvariantCulture);
            marketSlice.VolumeQuote = quoteVolume.ToString(CultureInfo.InvariantCulture);

            var model = new MarketDataViewModel
            {
                From         = nowDate - _marketDataInterval,
                To           = nowDate,
                Slice        = marketSlice,
                BaseVolumes  = baseVolumes,
                QuoteVolumes = quoteVolumes,
                PriceValues  = prices
            };

            return(View(model));
        }