Ejemplo n.º 1
0
        // TODO this is replace, not merge
        public override async Task StoreCollection(StatCollection collection, bool force)
        {
            while (true)
            {
                Task redisResponse;
                lock (collection)
                {
                    if (collection.Records.Count == 0 || !collection.IsDirty)
                    {
                        return;
                    }
                    if (!force && collection.Saved.AddSeconds(15) > DateTime.UtcNow)
                    {
                        return;
                    }
                    if (collection.RedisSet == null)
                    {
                        foreach (var record in collection.Records.Values)
                        {
                            record.RemoteAggCash += record.AggCash;
                            record.RemoteCount += record.Count;
                            record.Count = 0;
                            record.AggCash = 0;
                            if (record.RemoteCount > 1000000)
                            {
                                record.RemoteAggCash /= 1000;
                                record.RemoteCount /= 1000;
                            }
                        }
                        collection.Saved = DateTime.UtcNow;
                        collection.IsDirty = false;

                        var json = JsonSerializer.SerializeToString(collection);
                        if (json.Length > 50000)
                        {
                            throw new InvalidOperationException(collection.Key + "   " + json.Length);
                        }
                        collections[collection.Key] = json;
                        redisResponse = Task.Delay(10);

                        collection.RedisSet = redisResponse;
                    }
                    else
                    {
                        redisResponse = collection.RedisSet;
                    }
                }

                await redisResponse;

                lock (collection)
                {
                    if (collection.RedisSet == redisResponse)
                    {
                        Console.Write("S");
                        collection.RedisSet = null;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public async virtual Task<StatCollection> GetCollection(int bucketHash)
 {
     StatCollection collection;
     int collectionKey = bucketHash % Collections;
     if (!MemoryCache.TryGetValue(collectionKey, out collection))
     {
         collection = new StatCollection(collectionKey);
         collection = MemoryCache.Set<StatCollection>(collectionKey, collection, BucketOptions);
     }
     return collection;
 }
Ejemplo n.º 3
0
 public async virtual Task StoreCollection(StatCollection collection, bool force)
 {
 }
Ejemplo n.º 4
0
 public StatRecord(StatCollection collection)
 {
     Collection = collection;
 }