コード例 #1
0
        public RedisBool HMSet(RedisParam key, Hashtable values)
        {
            if (key.IsNull)
            {
                throw new ArgumentNullException("key");
            }

            if (values.IsEmpty())
            {
                throw new ArgumentNullException("values");
            }

            ValidateNotDisposed();

            var parameters = new byte[1 + (2 * values.Count)][];

            parameters[0] = key;

            var i = 1;

            foreach (DictionaryEntry de in values)
            {
                parameters[i++] = de.Key.ToBytes();
                parameters[i++] = de.Value.ToBytes();
            }
            return(ExpectOK(RedisCommandList.HMSet, parameters));
        }
コード例 #2
0
        public RedisBool HMSet(RedisParam key, RedisParam field, RedisParam value, RedisParam[] fields = null, RedisParam[] values = null)
        {
            if (key.IsNull)
            {
                throw new ArgumentNullException("key");
            }

            if (field.IsEmpty)
            {
                throw new ArgumentNullException("field");
            }

            ValidateNotDisposed();

            if (value.Length > RedisConstants.MaxValueLength)
            {
                throw new ArgumentException("value is limited to 1GB", "value");
            }

            if (fields.Length > 0)
            {
                if (values == null || values.Length != fields.Length)
                {
                    throw new ArgumentException("Field and values length does not match", "field");
                }

                var parameters = key
                                 .Join(field)
                                 .Join(value)
                                 .Join(fields.Merge(values));

                return(ExpectOK(RedisCommandList.HMSet, parameters));
            }
            return(ExpectOK(RedisCommandList.HMSet, key, field, value));
        }
コード例 #3
0
        public RedisBool Restore(RedisParam key, long ttl, RedisParam value)
        {
            ValidateNotDisposed();
            ValidateKeyAndValue(key, value);

            return(ExpectOK(RedisCommandList.Rename, key, ttl.ToBytes(), value));
        }
コード例 #4
0
        public RedisBool HMSet(RedisParam key, IDictionary <RedisParam, RedisParam> values)
        {
            if (key.IsNull)
            {
                throw new ArgumentNullException("key");
            }

            if (values == null || values.Count == 0)
            {
                throw new ArgumentNullException("values");
            }

            ValidateNotDisposed();

            var parameters = new byte[1 + (2 * values.Count)][];

            parameters[0] = key;

            var i = 1;

            foreach (var kvp in values)
            {
                parameters[i++] = kvp.Key;
                parameters[i++] = kvp.Value;
            }
            return(ExpectOK(RedisCommandList.HMSet, parameters));
        }
コード例 #5
0
        public bool Watch(RedisParam key, params RedisParam[] keys)
        {
            ValidateNotDisposed();

            if (Interlocked.Read(ref m_State) == (long)RedisBatchState.Executing)
            {
                throw new RedisException("Transaction is being executed", RedisErrorCode.ExecutionError);
            }

            var queue = m_WatchQ;

            if (queue == null)
            {
                queue = m_WatchQ = new ConcurrentQueue <RedisParam>();
            }

            if (!key.IsEmpty)
            {
                queue.Enqueue(key);
            }

            var length = keys.Length;

            if (length > 0)
            {
                foreach (var k in keys)
                {
                    if (!k.IsEmpty)
                    {
                        queue.Enqueue(k);
                    }
                }
            }
            return(true);
        }
コード例 #6
0
        public RedisResult <IDictionary <string, string> > ConfigGet(RedisParam parameter)
        {
            if (parameter.IsNull)
            {
                throw new ArgumentNullException("parameter");
            }

            var lines = ExpectMultiDataStrings(RedisCommandList.Config, RedisCommandList.Get, parameter.ToBytes());

            if (lines != null)
            {
                var linesLength = lines.Length;
                if (lines.Length > 0)
                {
                    var result = new Dictionary <string, string>(linesLength / 2);
                    for (var i = 0; i < linesLength; i += 2)
                    {
                        var key = (lines[i] ?? String.Empty).Trim();
                        if (!key.IsEmpty())
                        {
                            result[key] = (lines[i + 1] ?? String.Empty).Trim();
                        }
                    }
                    return(new RedisResult <IDictionary <string, string> >(result));
                }
            }
            return(new RedisResult <IDictionary <string, string> >(null));
        }
コード例 #7
0
        public RedisInteger GeoAdd(RedisParam key, RedisGeospatialItem member, params RedisGeospatialItem[] members)
        {
            if (key.IsEmpty)
            {
                throw new ArgumentNullException("key");
            }

            if (member.IsEmpty)
            {
                throw new ArgumentNullException("member");
            }

            if (members.IsEmpty())
            {
                return(ExpectInteger(RedisCommandList.GeoAdd, key, member.Longitude.ToBytes(),
                                     member.Latitude.ToBytes(), member.Name.ToBytes()));
            }

            var parameters = key
                             .Join(member.Longitude.ToBytes())
                             .Join(member.Latitude.ToBytes())
                             .Join(member.Name.ToBytes());

            foreach (var m in members)
            {
                parameters = parameters
                             .Join(m.Longitude.ToBytes())
                             .Join(m.Latitude.ToBytes())
                             .Join(m.Name.ToBytes());
            }

            return(ExpectInteger(RedisCommandList.GeoAdd, parameters));
        }
コード例 #8
0
        public RedisMultiBytes GeoHash(RedisParam key, RedisParam member, params RedisParam[] members)
        {
            if (key.IsEmpty)
            {
                throw new ArgumentNullException("key");
            }

            if (member.IsEmpty)
            {
                throw new ArgumentNullException("member");
            }

            if (members.IsEmpty())
            {
                return(ExpectMultiDataBytes(RedisCommandList.GeoHash, key, member));
            }

            var parameters = key.Join(member);

            foreach (var m in members)
            {
                if (!m.IsEmpty)
                {
                    parameters = parameters.Join(m);
                }
            }

            return(ExpectMultiDataBytes(RedisCommandList.GeoHash, parameters));
        }
コード例 #9
0
        public RedisScanStrings HScanString(RedisParam key, ulong cursor = 0uL, int count = 10, RedisParam?match = null)
        {
            if (key.IsNull)
            {
                throw new ArgumentNullException("key");
            }

            ValidateNotDisposed();

            var parameters = new byte[][] { key.Data, cursor.ToBytes() };

            if (match.HasValue)
            {
                var value = match.Value;
                if (!value.IsEmpty)
                {
                    parameters = parameters.Join(RedisCommandList.Match);
                    parameters = parameters.Join(value.Data);
                }
            }

            if (count > 0)
            {
                parameters = parameters.Join(RedisCommandList.Count);
                parameters = parameters.Join(count.ToBytes());
            }

            return(RedisCommandUtils.ToScanStrings(ExpectArray(RedisCommandList.HScan, parameters)));
        }
コード例 #10
0
 public void UnregisterSubscription(RedisParam channel, Action <RedisPubSubMessage> callback)
 {
     lock (m_SubscriptionLock)
     {
         m_PendingSubscriptions.Unregister(channel, callback);
         m_Subscriptions.Unregister(channel, callback);
     }
 }
コード例 #11
0
 public RedisString Ping(RedisParam msg)
 {
     if (msg.IsEmpty)
     {
         return(ExpectSimpleString(RedisCommandList.Ping));
     }
     return(ExpectBulkString(RedisCommandList.Ping, msg));
 }
コード例 #12
0
        public RedisBool LInsert(RedisParam key, bool insertBefore, RedisParam pivot, RedisParam value)
        {
            ValidateKeyAndValue(key, value);

            var prePost = insertBefore ? RedisCommandList.Before : RedisCommandList.After;

            return(ExpectOK(RedisCommandList.LInsert, key, prePost, pivot, value));
        }
コード例 #13
0
        public RedisString GetRangeString(RedisParam key, int start, int end)
        {
            if (key.IsEmpty)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectBulkString(RedisCommandList.GetRange, key, start.ToBytes(), end.ToBytes()));
        }
コード例 #14
0
        public RedisDouble IncrByFloat(RedisParam key, double increment)
        {
            if (key.IsEmpty)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectDouble(RedisCommandList.IncrBy, key, increment.ToBytes()));
        }
コード例 #15
0
        public RedisInteger HLen(RedisParam key)
        {
            if (key.IsNull)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectInteger(RedisCommandList.HLen, key));
        }
コード例 #16
0
        public RedisMultiString BRPopString(RedisParam key, int timeout)
        {
            if (key.IsNull)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectMultiDataStrings(RedisCommandList.BRPop, key, timeout.ToBytes()));
        }
コード例 #17
0
        public RedisString RPopString(RedisParam key)
        {
            if (key.IsNull)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectBulkString(RedisCommandList.RPop, key));
        }
コード例 #18
0
        public RedisBool LTrim(RedisParam key, int start, int end)
        {
            if (key.IsNull)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectOK(RedisCommandList.LTrim, key, start.ToBytes(), end.ToBytes()));
        }
コード例 #19
0
        public RedisInteger Decr(RedisParam key)
        {
            if (key.IsEmpty)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectInteger(RedisCommandList.Decr, key));
        }
コード例 #20
0
        public RedisString LIndexString(RedisParam key, int index)
        {
            if (key.IsNull)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectBulkString(RedisCommandList.LIndex, key, index.ToBytes()));
        }
コード例 #21
0
        public RedisInteger SetBit(RedisParam key, int offset, int value)
        {
            if (key.IsEmpty)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectInteger(RedisCommandList.SetBit, key, offset.ToBytes(), value.ToBytes()));
        }
コード例 #22
0
        public RedisMultiString HValStrings(RedisParam key)
        {
            if (key.IsNull)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectMultiDataStrings(RedisCommandList.HVals, key));
        }
コード例 #23
0
        public RedisBytes Get(RedisParam key)
        {
            if (key.IsEmpty)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectBulkStringBytes(RedisCommandList.Get, key));
        }
コード例 #24
0
        public RedisInteger DecrBy(RedisParam key, long count)
        {
            if (key.IsEmpty)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectInteger(RedisCommandList.DecrBy, key, count.ToBytes()));
        }
コード例 #25
0
        public RedisMultiString Keys(RedisParam pattern)
        {
            if (pattern.IsNull)
            {
                throw new ArgumentNullException("pattern");
            }

            return(ExpectMultiDataStrings(RedisCommandList.Keys, pattern));
        }
コード例 #26
0
        public RedisMultiString LRangeString(RedisParam key, int start, int end)
        {
            if (key.IsNull)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectMultiDataStrings(RedisCommandList.LRange, key, start.ToBytes(), end.ToBytes()));
        }
コード例 #27
0
        public RedisBool Auth(RedisParam password)
        {
            if (password.IsEmpty)
            {
                throw new ArgumentNullException("password");
            }

            return(ExpectOK(RedisCommandList.Auth, password));
        }
コード例 #28
0
        public RedisInteger BitCount(RedisParam key, int start, int end)
        {
            if (key.IsEmpty)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectInteger(RedisCommandList.BitCount, key, start.ToBytes(), end.ToBytes()));
        }
コード例 #29
0
        public RedisMultiBytes HGetAll(RedisParam key)
        {
            if (key.IsNull)
            {
                throw new ArgumentNullException("key");
            }

            return(ExpectMultiDataBytes(RedisCommandList.HGetAll, key));
        }
コード例 #30
0
        public RedisString Echo(RedisParam msg)
        {
            if (msg.IsNull)
            {
                throw new ArgumentNullException("msg");
            }

            return(ExpectBulkString(RedisCommandList.Echo, msg));
        }