Esempio n. 1
0
        /// <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));
        }
Esempio n. 2
0
        /// <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));
        }
Esempio n. 3
0
        /// <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));
        }
Esempio n. 4
0
        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;
            }
        }
Esempio n. 5
0
        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)));
        }
Esempio n. 6
0
 public IncrementRequest(CallBackPolicy callBackPolicy)
     : base(callBackPolicy)
 {
     RequestOpcode = Opcode.Increment;
 }
Esempio n. 7
0
        /// <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));
        }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
 /// <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));
 }
Esempio n. 10
0
 /// <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));
 }
Esempio n. 11
0
 /// <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
     }));
 }
Esempio n. 12
0
 /// <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
     }));
 }
Esempio n. 13
0
 /// <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
     }));
 }
Esempio n. 14
0
        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);
            }
        }
Esempio n. 15
0
 public DeleteRequest(CallBackPolicy callBackPolicy)
     : base(callBackPolicy)
 {
 }