public void Disconnect() { CheckConnected(); ((IActorClientProxy)_actor).Close(); _actor = null; _connectionInfo = null; }
/// <summary> /// 移除并返回列表中最后一个元素。 /// </summary> /// <param name="key">主键。</param> public async Task <T> RightPopListCacheAsync <T>(string key) { if (key.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(key)); } ICacheActor cacheActor = ActorProxy.Create <ICacheActor>(s_actorId, s_serviceUri); string response = await cacheActor.RightPopListCacheAsync(key); return(response.FromJson <T>()); }
/// <param name="connectionInfo">tcp://localhost:4632</param> public void Connect(ConnectionInfo connectionInfo) { if (connectionInfo == null) throw new ArgumentNullException(nameof(connectionInfo)); if (_actor != null) throw new InvalidOperationException("Already connected"); connectionInfo.Freeze(); _actor = ActorClientProxy.CreateActor<ICacheActor>(connectionInfo.EndPoint).Result; _connectionInfo = connectionInfo; }
/// <summary> /// 刷新列表缓存。 /// </summary> /// <param name="key">主键。</param> /// <param name="options">The options.</param> public async Task RefreshListCacheAsync(string key, KolibreCacheOptions options) { if (key.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(key)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } ICacheActor cacheActor = ActorProxy.Create <ICacheActor>(s_actorId, s_serviceUri); await cacheActor.RefreshListCacheAsync(key, options); }
/// <summary> /// 向列表尾添加元素,若 key 对应无列表缓存,则自动创建并添加一个元素。 /// </summary> /// <param name="key">主键。</param> /// <param name="value">要缓存的值。</param> /// <param name="options">缓存时间设置,为 NULL 表示永久。</param> public async Task RightPushListCacheAsync <T>(string key, T value, KolibreCacheOptions options) { if (key.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(key)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } ICacheActor cacheActor = ActorProxy.Create <ICacheActor>(s_actorId, s_serviceUri); await cacheActor.RightPushListCacheAsync(key, value.ToJson(), options); }
/// <summary> /// 获取 Hash 主键+次键对应的缓存。 /// </summary> /// <param name="firstKey">主键。</param> /// <param name="secondKey">次键,为空则返回主键对应的缓存。</param> public async Task <T> GetHashCacheAsync <T>(string firstKey, string secondKey) { if (firstKey.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(firstKey)); } if (secondKey.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(secondKey)); } ICacheActor cacheActor = ActorProxy.Create <ICacheActor>(s_actorId, s_serviceUri); string response = await cacheActor.GetHashCacheAsync(firstKey, secondKey); return(response.FromJson <T>()); }
/// <summary> /// 设置 Hash 缓存。 /// </summary> /// <param name="firstKey">主键。</param> /// <param name="secondKey">次键。</param> /// <param name="value">要缓存的值。</param> /// <param name="options">缓存时间设置,为 NULL 表示永久。</param> public async Task SetHashCacheAsync <T>(string firstKey, string secondKey, T value, KolibreCacheOptions options) { if (firstKey.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(firstKey)); } if (secondKey.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(secondKey)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } ICacheActor cacheActor = ActorProxy.Create <ICacheActor>(s_actorId, s_serviceUri); await cacheActor.SetHashCacheAsync(firstKey, secondKey, value.ToJson(), options); }