public void Set(string key, byte[] bytes) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentException("key is empty"); } _client.GetCacheClient().Set(key, bytes); }
public void PooledRedisClientManager_alternates_hosts() { using (var redisManager = new PooledRedisClientManager(MasterHosts, SlaveHosts)) { using (var master = redisManager.GetClient()) { Assert.That(master.GetHostString(), Is.EqualTo(MasterHosts[0])); master.SetValue("KEY", "1"); } using (var master = redisManager.GetClient()) { Assert.That(master.GetHostString(), Is.EqualTo(MasterHosts[0])); master.Increment("KEY", 1); } 5.Times(i => { using (var readOnly = redisManager.GetReadOnlyClient()) { Assert.That(readOnly.GetHostString(), Is.EqualTo(SlaveHosts[i % SlaveHosts.Length])); Assert.That(readOnly.GetValue("KEY"), Is.EqualTo("2")); } }); using (var cahce = redisManager.GetCacheClient()) { Assert.That(cahce.Get <string>("KEY"), Is.EqualTo("2")); } } }
public void PooledRedisClientManager_alternates_hosts() { using (var redisManager = new PooledRedisClientManager(MasterHosts, SlaveHosts)) { using (var master = redisManager.GetClient()) { Assert.That(master.GetHostString(), Is.EqualTo(MasterHosts[0])); master.SetValue("KEY", "1"); } using (var master = redisManager.GetClient()) { Assert.That(master.GetHostString(), Is.EqualTo(MasterHosts[0])); master.Increment("KEY", 1); } 5.Times(i => { using (var readOnly = redisManager.GetReadOnlyClient()) { Assert.That(readOnly.GetHostString(), Is.EqualTo(SlaveHosts[i % SlaveHosts.Length])); Assert.That(readOnly.GetValue("KEY"), Is.EqualTo("2")); } }); using (var cahce = redisManager.GetCacheClient()) { Assert.That(cahce.Get<string>("KEY"), Is.EqualTo("2")); } } }
/// <summary> /// 客户端缓存操作对象 /// </summary> public static ICacheClient GetCacheClient() { if (prcm == null) CreateManager(); return prcm.GetCacheClient(); }
public void PooledRedisClientManager_alternates_hosts() { using (var redisManager = new PooledRedisClientManager(Config.MasterHosts, Config.SlaveHosts)) { using (var master = redisManager.GetClient()) { Assert.That(master.GetHostString(), Is.EqualTo(Config.Sentinel6380)); master.SetValue("KEY", "1"); } using (var master = redisManager.GetClient()) { Assert.That(master.GetHostString(), Is.EqualTo(Config.Sentinel6380)); master.Increment("KEY", 1); } for (var i = 0; i < 5; i++) { using (var readOnly = redisManager.GetReadOnlyClient()) { Assert.That(readOnly.GetHostString(), Is.EqualTo(Config.Sentinel6381).Or.EqualTo(Config.Sentinel6382)); Assert.That(readOnly.GetValue("KEY"), Is.EqualTo("2")); } } using (var cache = redisManager.GetCacheClient()) { Assert.That(cache.Get <string>("KEY"), Is.EqualTo("2")); } } }
private void button4_Click(object sender, EventArgs e) { for (int i = 0; i < 10; i++) { ICacheClient client1 = prcm.GetCacheClient(); client1.Dispose(); } }
/// <summary> /// 获取缓存Client /// </summary> public ICacheClient GetCacheClient() { if (_prcm == null) { CreateManager(); } return(_prcm.GetCacheClient()); }
/// <summary> /// 获取缓存Client /// </summary> public ICacheClient GetCacheClient() { if (_redisClientManager == null) { CreateManager(); } return(_redisClientManager.GetCacheClient()); }
public override void Configure(Container container) { var configurationBuilder = new ConfigurationBuilder() .SetBasePath(AppContext.BaseDirectory) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); AppSettings = new NetCoreAppSettings(configurationBuilder.Build()); var redisFactory = new PooledRedisClientManager( AppSettings.GetString(AppSettingsKeys.RedisConnection)); var mqServer = new RedisMqServer(redisFactory, retryCount: AppSettings.Get <int>(AppSettingsKeys.RedisRetries)); var cacheClient = redisFactory.GetCacheClient(); var jobGroupId = AppSettings.GetString(AppSettingsKeys.JobGroupId); var jobCompletedCacheKey = CacheKeys.JobCompleted <JobResponse>(jobGroupId); var numberOfJobs = AppSettings.Get <int>(AppSettingsKeys.NumberOfJobs); cacheClient.Remove(jobCompletedCacheKey); mqServer.RegisterHandler <JobResponse>(m => { Console.WriteLine("Received: " + m.GetBody().Result); cacheClient.Increment(jobCompletedCacheKey, 1); if (cacheClient.Get <int>(jobCompletedCacheKey) >= numberOfJobs) { appLifetime.StopApplication(); } return(null); }); AfterInitCallbacks.Add(host => { mqServer.Start(); var mqClient = mqServer.CreateMessageQueueClient(); for (var i = 1; i <= numberOfJobs; i++) { mqClient.Publish(new JobRequest { JobId = Guid.NewGuid().ToString(), GroupId = jobGroupId, Description = $"Job {i}" }); } }); }