Пример #1
0
        /// <summary>
        /// Sets the specified fields to their respective values in the hash stored at key.
        /// This command overwrites any existing fields in the hash. If key does not exist, a new key holding a hash is created.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="values"></param>
        /// <param name="asyncState"></param>
        /// <returns></returns>
        Task IHashCommands.Set(string key, Dictionary <string, byte[]> values, object asyncState)
        {
            if (values == null || values.Count == 0)
            {
                throw new ArgumentNullException("values is null or empty.");
            }

            var request = new RedisRequest(2 + values.Count * 2).AddArgument("HMSET").AddArgument(key);

            foreach (var child in values)
            {
                request.AddArgument(child.Key).AddArgument(child.Value);
            }
            return(this.ExecuteStatusReply(request, asyncState));
        }
Пример #2
0
        /// <summary>
        /// Returns the values associated with the specified fields in the hash stored at key.
        /// For every field that does not exist in the hash, a nil value is returned.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="fields"></param>
        /// <param name="asyncState"></param>
        /// <returns>list of values associated with the given fields, in the same order as they are requested.</returns>
        Task <byte[][]> IHashCommands.Get(string key, string[] fields, object asyncState)
        {
            if (fields == null || fields.Length == 0)
            {
                throw new ArgumentNullException("fields is null or empty.");
            }

            var request = new RedisRequest(fields.Length + 2).AddArgument("HMGET").AddArgument(key);

            for (int i = 0, l = fields.Length; i < l; i++)
            {
                request.AddArgument(fields[i]);
            }
            return(this.ExecuteMultiBulkReplies(request, asyncState));
        }
Пример #3
0
        /// <summary>
        /// Removes the specified fields from the hash stored at key.
        /// Specified fields that do not exist within this hash are ignored.
        /// If key does not exist, it is treated as an empty hash and this command returns 0.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="fields"></param>
        /// <param name="asyncState"></param>
        /// <returns>
        /// the number of fields that were removed from the hash, not including specified but non existing fields.
        /// </returns>
        /// <exception cref="ArgumentNullException">fields is null or empty.</exception>
        Task <int> IHashCommands.Remove(string key, string[] fields, object asyncState)
        {
            if (fields == null || fields.Length == 0)
            {
                throw new ArgumentNullException("fields is null or empty.");
            }

            var request = new RedisRequest(fields.Length + 2).AddArgument("HDEL").AddArgument(key);

            for (int i = 0, l = fields.Length; i < l; i++)
            {
                request.AddArgument(fields[i]);
            }

            return(this.ExecuteIntegerReply(request, asyncState));
        }
Пример #4
0
        /// <summary>
        /// Sets the given keys to their respective values.
        /// MSET replaces existing values with new values, just as regular SET. See MSETNX if you don't want to overwrite existing values.
        /// MSET is atomic, so all given keys are set at once.
        /// It is not possible for clients to see that some of the keys were updated while others are unchanged.
        /// </summary>
        /// <param name="dic"></param>
        /// <param name="asyncState"></param>
        /// <returns>always OK since MSET can't fail.</returns>
        /// <exception cref="ArgumentNullException">dic is null or empty.</exception>
        Task IStringCommands.Set(Dictionary <string, byte[]> dic, object asyncState)
        {
            if (dic == null || dic.Count == 0)
            {
                throw new ArgumentNullException("dic", "dic is null or empty.");
            }

            var request = new RedisRequest(dic.Count + dic.Count + 1).AddArgument("MSET");

            foreach (var kv in dic)
            {
                request.AddArgument(kv.Key).AddArgument(kv.Value);
            }

            return(this.ExecuteStatusReply(request, asyncState));
        }
Пример #5
0
        /// <summary>
        /// unsubscribe pattern
        /// </summary>
        /// <param name="patterns"></param>
        private void UnPatternSubscribeInternal(string[] patterns)
        {
            if (patterns == null || patterns.Length == 0)
            {
                return;
            }

            var connection = this._currentConnection;

            if (connection == null)
            {
                return;
            }

            var r = new RedisRequest(patterns.Length + 1).AddArgument("PUNSUBSCRIBE");

            foreach (var pattern in patterns)
            {
                r.AddArgument(pattern);
            }

            connection.BeginSend(new Packet(r.ToPayload()));
        }
Пример #6
0
        /// <summary>
        /// unsubscribe channel
        /// </summary>
        /// <param name="channels"></param>
        private void UnSubscribeInternal(string[] channels)
        {
            if (channels == null || channels.Length == 0)
            {
                return;
            }

            var connection = this._currentConnection;

            if (connection == null)
            {
                return;
            }

            var r = new RedisRequest(channels.Length + 1).AddArgument("UNSUBSCRIBE");

            foreach (var channel in channels)
            {
                r.AddArgument(channel);
            }

            connection.BeginSend(new Packet(r.ToPayload()));
        }
        /// <summary>
        /// unsubscribe pattern
        /// </summary>
        /// <param name="patterns"></param>
        private void UnPatternSubscribeInternal(string[] patterns)
        {
            if (patterns == null || patterns.Length == 0) return;

            var connection = this._currentConnection;
            if (connection == null) return;

            var r = new RedisRequest(patterns.Length + 1).AddArgument("PUNSUBSCRIBE");
            foreach (var pattern in patterns) r.AddArgument(pattern);

            connection.BeginSend(new Packet(r.ToPayload()));
        }
        /// <summary>
        /// unsubscribe channel
        /// </summary>
        /// <param name="channels"></param>
        private void UnSubscribeInternal(string[] channels)
        {
            if (channels == null || channels.Length == 0) return;

            var connection = this._currentConnection;
            if (connection == null) return;

            var r = new RedisRequest(channels.Length + 1).AddArgument("UNSUBSCRIBE");
            foreach (var channel in channels) r.AddArgument(channel);

            connection.BeginSend(new Packet(r.ToPayload()));
        }