/// <summary> /// Fetch the value for the given key /// </summary> /// <param name="key" /> /// <param name="callback">Will be called after the memcached respond</param> /// <param name="callbackPolicy" /> /// <returns></returns> public bool Get(string key, Action <Status, byte[]> callback, CallBackPolicy callbackPolicy = CallBackPolicy.AnyOK) { var keyAsBytes = _configuration.KeySerializer.SerializeToBytes(key); var request = new GetRequest { Key = keyAsBytes, CallBack = callback, CallBackPolicy = callbackPolicy, RequestId = NextRequestId, Replicas = _configuration.Replicas, }; return(SendRequest(request)); }
/// <summary> /// Fetch the value for the given key /// </summary> /// <param name="key" /> /// <param name="callback">Will be called after the memcached respond</param> /// <param name="callbackPolicy" /> /// <returns></returns> public bool Get <T>(string key, Action <Status, T> callback, CallBackPolicy callbackPolicy = CallBackPolicy.AnyOK) { var keyAsBytes = _configuration.KeySerializer.SerializeToBytes(key); var serializer = _configuration.SerializerOf <T>(); var request = new GetRequest(callbackPolicy) { Key = keyAsBytes, CallBack = SanitizeCallback(callback, serializer), RequestId = NextRequestId, Replicas = _configuration.Replicas, }; return(SendRequest(request)); }
/// <summary> /// Delete the entry associated with the given key /// </summary> /// <param name="key" /> /// <param name="callback">Will be called after the memcached respond</param> /// <param name="callbackPolicy" /> /// <returns></returns> public bool Delete(string key, Action <Status> callback, CallBackPolicy callbackPolicy = CallBackPolicy.AllOK) { var keyAsBytes = _configuration.KeySerializer.SerializeToBytes(key); var request = new DeleteRequest { Key = keyAsBytes, CallBack = SanitizeCallback(callback), CallBackPolicy = callbackPolicy, RequestId = NextRequestId, Replicas = _configuration.Replicas }; return(SendRequest(request)); }
protected RedundantRequest(CallBackPolicy callBackPolicy) { _callBackPolicy = callBackPolicy; switch (_callBackPolicy) { case CallBackPolicy.AnyOK: _aggregatedStatus = (int)Status.InternalError; break; case CallBackPolicy.AllOK: _aggregatedStatus = (int)Status.NoError; break; default: _aggregatedStatus = (int)Status.InternalError; break; } }
public void ResultAggregationTest(Status[] statuses, CallBackPolicy callBackPolicy, Status expectedResult) { Status result = Status.UnknownCommand; var request = new GetRequest(callBackPolicy) { Key = "Hello".Select(c => (byte)c).ToArray(), RequestId = 0, CallBack = (s, m) => result = s, Replicas = statuses.Length - 1, }; foreach (var status in statuses) { request.HandleResponse(new MemcacheResponseHeader { Opcode = Opcode.Get, Status = status }, null, GET_FLAG, GET_MESSAGE); } Assert.AreEqual(expectedResult, result, string.Format("Input statuses: [{0}]", string.Join(", ", statuses))); }
public IncrementRequest(CallBackPolicy callBackPolicy) : base(callBackPolicy) { RequestOpcode = Opcode.Increment; }
/// <summary> /// Fetch the value for the given key /// and prolongs it to the given TTL /// </summary> /// <param name="key" /> /// <param name="expire" /> /// <param name="callback">Will be called after the memcached respond</param> /// <param name="callbackPolicy" /> /// <returns></returns> public bool GetAndTouch(string key, TimeSpan expire, Action <Status, byte[]> callback, CallBackPolicy callbackPolicy = CallBackPolicy.AnyOK) { var keyAsBytes = _configuration.KeySerializer.SerializeToBytes(key); var request = new GetRequest { RequestOpcode = Opcode.GAT, Expire = expire, Key = keyAsBytes, CallBack = callback, CallBackPolicy = callbackPolicy, RequestId = NextRequestId, Replicas = _configuration.Replicas }; return(SendRequest(request)); }
public bool Store(StoreMode mode, string key, byte[] message, TimeSpan expiration, Action <Status> callback = null, CallBackPolicy callbackPolicy = CallBackPolicy.AllOK) { Opcode op; if (mode == StoreMode.Add) { op = Opcode.Add; } else if (mode == StoreMode.Replace) { op = Opcode.Replace; } else if (mode == StoreMode.Set) { op = Opcode.Set; } else { throw new ArgumentException("Unsupported operation " + mode); } var keyAsBytes = _configuration.KeySerializer.SerializeToBytes(key); var request = new SetRequest { Key = keyAsBytes, Message = message, Expire = expiration, RequestId = NextRequestId, CallBack = callback, CallBackPolicy = callbackPolicy, Replicas = _configuration.Replicas, RequestOpcode = op, }; return(SendRequest(request)); }
/// <summary> /// Sets the key with the given message with the given TTL /// Fails if the key already exists (KeyExists as status on callback) /// </summary> /// <param name="key" /> /// <param name="message" /> /// <param name="expiration" /> /// <param name="callback">Will be called after the memcached respond</param> /// <param name="callbackPolicy" /> /// <returns></returns> public bool Add(string key, byte[] message, TimeSpan expiration, Action <Status> callback = null, CallBackPolicy callbackPolicy = CallBackPolicy.AllOK) { return(Store(StoreMode.Add, key, message, expiration, callback, callbackPolicy)); }
/// <summary> /// Sets the key with the given message with the given TTL /// Fails if the key doesn't exists (KeyNotFound as status on callback) /// </summary> /// <param name="key" /> /// <param name="message" /> /// <param name="expiration" /> /// <param name="callback">Will be called after the memcached respond</param> /// <param name="callbackPolicy" /> /// <returns></returns> public bool Update <T>(string key, T message, TimeSpan expiration, Action <Status> callback = null, CallBackPolicy callbackPolicy = CallBackPolicy.AllOK) { return(Store(StoreMode.Replace, key, message, expiration, callback, callbackPolicy)); }
/// <summary> /// Delete the entry associated with the given key /// </summary> /// <param name="key" /> /// <param name="callback">Will be called after the memcached respond</param> /// <returns></returns> public bool Delete(string key, Action <Status> callback, CallBackPolicy callbackPolicy = CallBackPolicy.AllOK) { return(SendRequest(new DeleteRequest { Key = key, CallBack = callback, CallBackPolicy = callbackPolicy, RequestId = NextRequestId, Replicas = _configuration.Replicas })); }
/// <summary> /// Fetch the value for the given key /// and prolongs it to the given TTL /// </summary> /// <param name="key" /> /// <param name="expire" /> /// <param name="callback">Will be called after the memcached respond</param> /// <returns></returns> public bool GetAndTouch(string key, TimeSpan expire, Action <Status, byte[]> callback, CallBackPolicy callbackPolicy = CallBackPolicy.AnyOK) { return(SendRequest(new GetRequest { RequestOpcode = Opcode.GAT, Expire = expire, Key = key, CallBack = callback, CallBackPolicy = callbackPolicy, RequestId = NextRequestId, Replicas = _configuration.Replicas })); }
/// <summary> /// Fetch the value for the given key /// </summary> /// <param name="key" /> /// <param name="callback">Will be called after the memcached respond</param> /// <returns></returns> public bool Get(string key, Action <Status, byte[]> callback, CallBackPolicy callbackPolicy = CallBackPolicy.AnyOK) { return(SendRequest(new GetRequest { Key = key, CallBack = callback, CallBackPolicy = callbackPolicy, RequestId = NextRequestId, Replicas = _configuration.Replicas })); }
public bool Store(StoreMode mode, string key, byte[] message, TimeSpan expiration, Action <Status> callback = null, CallBackPolicy callbackPolicy = CallBackPolicy.AllOK) { switch (mode) { case StoreMode.Set: return(SendRequest(new SetRequest { Key = key, Message = message, Expire = expiration, RequestId = NextRequestId, CallBack = callback, CallBackPolicy = callbackPolicy, Replicas = _configuration.Replicas })); case StoreMode.Replace: return(SendRequest(new SetRequest { Key = key, Message = message, Expire = expiration, RequestId = NextRequestId, CallBack = callback, CallBackPolicy = callbackPolicy, Replicas = _configuration.Replicas, RequestOpcode = Opcode.Replace })); case StoreMode.Add: return(SendRequest(new SetRequest { Key = key, Message = message, Expire = expiration, RequestId = NextRequestId, CallBack = callback, CallBackPolicy = callbackPolicy, Replicas = _configuration.Replicas, RequestOpcode = Opcode.Add })); default: return(false); } }
public DeleteRequest(CallBackPolicy callBackPolicy) : base(callBackPolicy) { }