private void Initialize(IRedisClientConfiguration configuration) { IServerPool pool = new DefaultServerPool(configuration); Initialize(pool); _serverPool = pool; _currentDb = configuration.DefaultDB; // ??? _commandQueues = new Dictionary<IRedisNode, RedisCommandQueue>(); }
/// <summary> /// new /// </summary> /// <param name="protocol"></param> /// <param name="socketBufferSize"></param> /// <param name="messageBufferSize"></param> /// <param name="millisecondsSendTimeout"></param> /// <param name="millisecondsReceiveTimeout"></param> /// <exception cref="ArgumentNullException">protocol is null</exception> public PooledSocketClient(Protocol.IProtocol <TResponse> protocol, int socketBufferSize, int messageBufferSize, int millisecondsSendTimeout, int millisecondsReceiveTimeout) : base(protocol, socketBufferSize, messageBufferSize, millisecondsSendTimeout, millisecondsReceiveTimeout) { this._serverPool = this.InitServerPool(); this._serverPool.Connected += this.OnServerPoolConnected; }
public static ICachedumpOperationResult Cachedump(this MemcachedClient client, int slab = 1, int limit = 0) { #region 反射获取 IServerPool 属性值 Type t = client.GetType(); PropertyInfo prop_Pool = t.GetProperty("Pool", BindingFlags.Instance | BindingFlags.NonPublic); PropertyInfo prop_KeyTransformer = t.GetProperty("KeyTransformer", BindingFlags.Instance | BindingFlags.NonPublic); IServerPool pool = prop_Pool.GetValue(client) as IServerPool; IMemcachedKeyTransformer keyTransformer = prop_KeyTransformer.GetValue(client) as IMemcachedKeyTransformer; #endregion string key = string.Format("{0} {1}", slab, limit); var hashedKey = keyTransformer.Transform(key.Replace(" ", "_")); var node = pool.Locate(hashedKey); ICachedumpOperationResultFactory CachedumpOperationResultFactory = new DefaultCachedumpOperationResultFactory(); var result = CachedumpOperationResultFactory.Create(); if (node != null) { var command = new CachedumpOperation(key); var commandResult = node.Execute(command); if (commandResult.Success) { result.Value = new Dictionary <string, string>(); command.Result.ForEach(item => { //item is: //ITEM testKey2 [3 b; 1600335168 s] //ITEM key_name [value_length b; expire_time | access_time s] // 0 1 2 3 4 5 //1.2.2- 访问时间(timestamp) //1.2.4+ 过期时间(timestamp) //如果是永不过期的key,expire_time会显示为服务器启动的时间 string[] parts = item.Split(' '); result.Value.Add(parts[1], string.Join(" ", parts, 2, parts.Length - 2)); }); result.Pass(); return(result); } else { commandResult.Combine(result); return(result); } } result.Fail("Unable to locate node"); return(result); }
public MemcachedClient(IServerPool pool, IMemcachedKeyTransformer keyTransformer, ITranscoder transcoder, IPerformanceMonitor performanceMonitor) { if (pool == null) throw new ArgumentNullException("pool"); if (keyTransformer == null) throw new ArgumentNullException("keyTransformer"); if (transcoder == null) throw new ArgumentNullException("transcoder"); this.performanceMonitor = performanceMonitor; this.keyTransformer = keyTransformer; this.transcoder = transcoder; this.pool = pool; this.StartPool(); }
/// <summary> /// Initializes a new instance of the <see cref="T:MemcachedClient"/> using the specified configuration instance. /// </summary> /// <param name="configuration">The memcachedClient configuration.</param> public MemcachedClient(IMemcachedClientConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } this.keyTransformer = configuration.CreateKeyTransformer() ?? new DefaultKeyTransformer(); this.transcoder = configuration.CreateTranscoder() ?? new DefaultTranscoder(); this.performanceMonitor = configuration.CreatePerformanceMonitor(); this.pool = configuration.CreatePool(); this.pool.Start(); }
/// <summary> /// Releases all resources allocated by this instance /// </summary> /// <remarks>You should only call this when you are not using static instances of the client, so it can close all conections and release the sockets.</remarks> public void Dispose() { GC.SuppressFinalize(this); if (this.pool != null) { try { this.pool.Dispose(); } finally { this.pool = null; } } if (this.performanceMonitor != null) { try { this.performanceMonitor.Dispose(); } finally { this.performanceMonitor = null; } } }
/// <summary> /// Initializes a new instance of the <see cref="T:MemcachedClient"/> using the specified configuration instance. /// </summary> /// <param name="configuration">The client configuration.</param> public MemcachedClient(IMemcachedClientConfiguration configuration) { if (configuration == null) throw new ArgumentNullException("configuration"); this.keyTransformer = configuration.CreateKeyTransformer() ?? new DefaultKeyTransformer(); this.transcoder = configuration.CreateTranscoder() ?? new DefaultTranscoder(); this.performanceMonitor = configuration.CreatePerformanceMonitor(); this.pool = configuration.CreatePool(); this.pool.NodeFailed += (n) => { var f = this.NodeFailed; if (f != null) f(n); }; this.StartPool(); StoreOperationResultFactory = new DefaultStoreOperationResultFactory(); GetOperationResultFactory = new DefaultGetOperationResultFactory(); MutateOperationResultFactory = new DefaultMutateOperationResultFactory(); ConcatOperationResultFactory = new DefaultConcatOperationResultFactory(); RemoveOperationResultFactory = new DefaultRemoveOperationResultFactory(); }
public bool TryCreate(string id, JObject config, out IServerPool pool) { pool = null; var d = (dynamic)config; var pId = (string)d?.provider; if (pId == null) { return(false); } var provider = serverProviders.FirstOrDefault(p => p.Type == pId); if (provider == null) { return(false); } pool = new ProviderBasedServerPool(id, provider, logger, gameSessions); return(true); }
public MemcachedClient(IServerPool pool, IMemcachedKeyTransformer keyTransformer, ITranscoder transcoder) : this(pool, keyTransformer, transcoder, null) { }
private static void Initialize(IServerPool pool) { // everything is initialized, start the pool pool.Start(); }
/// <summary> /// Releases all resources allocated by this instance /// </summary> /// <remarks>Technically it's not really neccesary to call this, since the client does not create "really" disposable objects, so it's safe to assume that when /// the AppPool shuts down all resources will be released correctly and no handles or such will remain in the memory.</remarks> protected override void Release() { if (_serverPool == null) throw new ObjectDisposedException("RedisClient"); try { FlushPipeline(); } finally { try { _serverPool.Dispose(); } finally { _serverPool = null; } } }
public bool TryCreate(string id, JObject config, out IServerPool pool) { pool = new CompositeServerPool(id, pools(), logger); return(true); }