public static async ETTask <List <long> > GetAllIds(this CacheProxyComponent self, string collectionName) { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); CacheGetAllIdsResponse cacheDeleteResponse = (CacheGetAllIdsResponse)await session.Call(new CacheGetAllIdsRequest { CollectionName = collectionName }); return(cacheDeleteResponse.IdList); }
public static async ETTask <bool> DeleteById <T>(this CacheProxyComponent self, long id) where T : ComponentWithId { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); CacheDeleteResponse cacheDeleteByIdResponse = (CacheDeleteResponse)await session.Call(new CacheDeleteByIdRequest { CollectionName = typeof(T).Name.ToLower(), Id = id }); return(cacheDeleteByIdResponse.IsSuccessful); }
public static async ETTask <bool> DeleteByUnique <T>(this CacheProxyComponent self, string uniqueName, BsonDocument condition) where T : ComponentWithId { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); CacheDeleteResponse cacheDeleteResponse = (CacheDeleteResponse)await session.Call(new CacheDeleteByUniqueRequest { CollectionName = typeof(T).Name.ToLower(), UniqueName = uniqueName, Json = condition.ToJson() }); return(cacheDeleteResponse.IsSuccessful); }
public static async ETTask <T> Create <T>(this CacheProxyComponent self, T entity) where T : ComponentWithId { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); CacheQueryResponse cacheCreateResponse = (CacheQueryResponse)await session.Call(new CacheCreateRequest { CollectionName = typeof(T).Name.ToLower(), Component = entity, }); return((T)cacheCreateResponse.Component); }
public static async ETTask <T> UpdateById <T>(this CacheProxyComponent self, long id, string updatedData) where T : ComponentWithId { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); CacheQueryResponse cacheUpdateByIdResponse = (CacheQueryResponse)await session.Call(new CacheUpdateByIdRequest { CollectionName = typeof(T).Name.ToLower(), Id = id, DataJson = updatedData, }); return((T)cacheUpdateByIdResponse.Component); }
public static async ETTask <T> QueryById <T>(this CacheProxyComponent self, string collectionName, long id, List <string> fields = null) where T : ComponentWithId { Session session = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress); CacheQueryResponse cacheQueryByIdResponse = (CacheQueryResponse)await session.Call(new CacheQueryByIdRequest { CollectionName = collectionName, Id = id, Fields = fields, }); return((T)cacheQueryByIdResponse.Component); }
public static void Awake(this RedisEventSolverComponent self, CacheProxyComponent cacheProxyComponent, Type type) { self.cacheProxyComponent = cacheProxyComponent; self.type = type; self.collectionName = type.Name.ToLower(); // 訂閱頻道 self.redisSubClient.GetSubscriber().Subscribe(self.channelDeleteKey, self.OnReceiveMessage); self.redisSubClient.GetSubscriber().Subscribe(self.channelUpdateKey, self.OnReceiveMessage); self.redisSubClient.GetSubscriber().Subscribe(self.channelCreateKey, self.OnReceiveMessage); self.redisSubClient.GetSubscriber().Subscribe(self.channelRefreshKey, self.OnReceiveMessage); }
public static async ETTask <T> UpdateById <T>(this CacheProxyComponent self, T entity) where T : ComponentWithId { // TODO:待觀察的Bug try { return(await self.UpdateById <T>(entity.Id, entity.ToBsonDocument().ToJson())); } catch (Exception ex) { Log.Error($"Type:{entity.GetType().Name}, Entity:{entity.Id}, Message:{ex.Message}, Stack:{ex.StackTrace}"); } return(null); }
public static void Awake(this CacheProxyComponent self) { StartConfig dbStartConfig = StartConfigComponent.Instance.DBConfig; self.dbAddress = dbStartConfig.GetComponent <InnerConfig>().IPEndPoint; CacheConfig cacheConfig = dbStartConfig.GetComponent <CacheConfig>(); if (cacheConfig == null) { self.connectionString = CacheComponent.connectionString; } else { self.connectionString = cacheConfig.ConnectionString; } Log.Info($"to prepare initializing redis......"); // to establish connection with Redis self.redisClient = ConnectionMultiplexer.Connect(self.connectionString); self.redisSubClient = ConnectionMultiplexer.Connect(self.connectionString); self.redisPubClient = ConnectionMultiplexer.Connect(self.connectionString); Log.Info($"to connect redis is successful."); var startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>(); foreach (var v in DBHelper.GetCacheUseModesIter()) { if (!CacheHelper.IsSyncOn(v.Key, startConfigComponent.StartConfig.AppType)) { continue; } switch (v.Value) { case CacheUseMode.MemorySyncByDB: break; case CacheUseMode.MemorySyncByRedis: var component = ComponentFactory.Create <RedisEventSolverComponent, CacheProxyComponent, Type>(self, v.Key); self.redisEventSolvers.Add(v.Key, component); break; } } }
public static async ETTask <bool> UnlockEvent(this CacheProxyComponent self, string key, string token) { return(await self.redisClient.GetDatabase().LockReleaseAsync(self.GetLockName(key), token)); }
public static async ETTask <bool> LockEvent(this CacheProxyComponent self, string key, string token, long timeout = 60000) { return(await self.redisClient.GetDatabase().LockTakeAsync(self.GetLockName(key), token, TimeSpan.FromMilliseconds(timeout))); }
public static async ETTask <T> UpdateById <T>(this CacheProxyComponent self, long id, BsonDocument updatedData) where T : ComponentWithId { return(await self.UpdateById <T>(id, updatedData.ToJson())); }
public static async ETTask <T> QueryById <T>(this CacheProxyComponent self, long id) where T : ComponentWithId { return(await self.QueryById <T>(typeof(T).Name.ToLower(), id)); }
public static void Destroy(this CacheProxyComponent self) { self.redisClient.Close(); self.redisSubClient.Close(); self.redisPubClient.Close(); }