/// <summary>
        /// Retrieve the value for the given key if present
        /// </summary>
        /// <param name="key" />
        /// <returns>The fetched value, null if not present or any error was raised from memcached</returns>
        public byte[] Get(string key)
        {
            var taskSource = new TaskCompletionSource <byte[]>();

            if (!_client.Get(
                    key: key,
                    callback: (s, m) =>
            {
                if (s == Status.NoError)
                {
                    taskSource.SetResult(m);
                }
                else
                {
                    taskSource.SetResult(null);
                }
            }))
            {
                taskSource.SetResult(null);
            }

            if (taskSource.Task.Wait(_receiveTimeout))
            {
                return(taskSource.Task.Result);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Retrieve the value for the given key if present
        /// </summary>
        /// <param name="key" />
        /// <returns>The fetched value, null if not present or any error was raised from memcached</returns>
        public byte[] Get(string key)
        {
            var taskSource = new TaskCompletionSource <byte[]>();

            if (!_client.Get(key, (s, m) => taskSource.SetResult(s == Status.NoError ? m : null)))
            {
                taskSource.SetResult(null);
            }

            if (!taskSource.Task.Wait(_receiveTimeout))
            {
                return(null);
            }

            return(taskSource.Task.Result);
        }
Exemple #3
0
        /// <summary>
        /// Retrieve the value for the given key if present
        /// </summary>
        /// <param name="key" />
        /// <returns>The fetched value, null if not present or any error was raised from memcached</returns>
        public T Get <T>(string key)
        {
            var taskSource = new TaskCompletionSource <T>();

            if (!_client.Get(key, (Status s, T m) => taskSource.SetResult(s == Status.NoError ? m : default(T))))
            {
                taskSource.SetResult(default(T));
            }

            if (!taskSource.Task.Wait(_receiveTimeout))
            {
                return(default(T));
            }

            return(taskSource.Task.Result);
        }