예제 #1
0
        public double HIncrByFloat(string key, string field, double incrementBy)
        {
            if (!this.IsValidField(field))
            {
                return(0.0);
            }

            RedisNativeClient client = this.pool.GetRedisClient(key);

            return((client == null) ? 0.0 : client.HIncrbyFloat(key, UTF8String.ToBytes(field), incrementBy));
        }
예제 #2
0
        public string GetValueFromHash(string hashId, string key)
        {
            if (!this.IsValidField(key))
            {
                return(null);
            }

            RedisNativeClient client = this.pool.GetRedisClient(hashId);

            return((client == null) ? null : UTF8String.ToString(client.HGet(hashId, UTF8String.ToBytes(key))));
        }
예제 #3
0
        public long HIncrBy(string key, string field, int incrementBy)
        {
            if (!this.IsValidField(field))
            {
                return(0L);
            }

            RedisNativeClient client = this.pool.GetRedisClient(key);

            return((client == null) ? 0L : client.HIncrby(key, UTF8String.ToBytes(field), incrementBy));
        }
예제 #4
0
        public bool SetValueIfNotExists(string key, string value, int expirySeconds)
        {
            if (!this.IsValidValue(value))
            {
                return(false);
            }

            RedisNativeClient client = this.pool.GetRedisClient(key);

            return((client == null) ? false : client.Set(key, UTF8String.ToBytes(value), exists: false, expirySeconds: expirySeconds));
        }
예제 #5
0
        public long HExists(string key, string field)
        {
            if (!this.IsValidField(field))
            {
                return(0L);
            }

            RedisNativeClient client = this.pool.GetRedisClient(key);

            return((client == null) ? 0L : client.HExists(key, UTF8String.ToBytes(field)));
        }
예제 #6
0
        public static byte[][] ToBytesArray(List <string> s)
        {
            var bytes = new byte[s.Count][];

            for (var i = 0; i < s.Count; ++i)
            {
                var item = s[i];
                bytes[i] = (item != null) ? UTF8String.ToBytes(item) : new byte[0];
            }
            return(bytes);
        }
예제 #7
0
        public static byte[][] ToBytesArray(string[] s)
        {
            var bytes = new byte[s.Length][];

            for (var i = 0; i < s.Length; i++)
            {
                var item = s[i];
                bytes[i] = (item != null) ? UTF8String.ToBytes(item) : new byte[0];
            }
            return(bytes);
        }
예제 #8
0
        public bool LSet(string key, int index, string value)
        {
            RedisNativeClient client = this.pool.GetRedisClient(key);

            if (client == null)
            {
                return(false);
            }

            client.LSet(key, index, UTF8String.ToBytes(value));
            return(true);
        }
예제 #9
0
        public long Append(string key, string value)
        {
            if (!this.IsValidValue(value))
            {
                return(0L);
            }

            // Get the corresponding Redis client.
            RedisNativeClient client = this.pool.GetRedisClient(key);

            return((client == null) ? 0L : client.Append(key, UTF8String.ToBytes(value)));
        }
예제 #10
0
        //------------------------------------------------------------------
        // STRING

        public bool Set(string key, string value)
        {
            if (!this.IsValidValue(value))
            {
                return(false);
            }

            // Get the corresponding Redis client.
            RedisNativeClient client = this.pool.GetRedisClient(key);

            if (client == null)
            {
                return(false);
            }

            client.Set(key, UTF8String.ToBytes(value));
            return(true);
        }
예제 #11
0
        public bool HMSet(string key, IEnumerable <KeyValuePair <string, string> > keyValuePairs)
        {
            int len = 0;

            foreach (KeyValuePair <string, string> node in keyValuePairs)
            {
                if (!this.IsValidField(node.Key) || !this.IsValidValue(node.Value))
                {
                    return(false);
                }
                len++;
            }
            if (len == 0)
            {
                return(false);
            }

            RedisNativeClient client = this.pool.GetRedisClient(key);

            if (client == null)
            {
                return(false);
            }

            var keys   = new byte[len][];
            var values = new byte[len][];
            int i      = 0;

            foreach (KeyValuePair <string, string> node in keyValuePairs)
            {
                keys[i]   = UTF8String.ToBytes(node.Key);
                values[i] = UTF8String.ToBytes(node.Value);
            }

            client.HMSet(key, keys, values);
            return(true);
        }
예제 #12
0
        public long HSetNx(string key, string field, string value)
        {
            RedisNativeClient client = this.pool.GetRedisClient(key);

            return((client == null) ? 0L : client.HSetNX(key, UTF8String.ToBytes(field), UTF8String.ToBytes(value)));
        }
예제 #13
0
        public long RPushX(string key, string value)
        {
            RedisNativeClient client = this.pool.GetRedisClient(key);

            return((client == null) ? 0L : client.RPushX(key, UTF8String.ToBytes(value)));
        }
예제 #14
0
        public long LRem(string key, int removeNoOfMatches, string value)
        {
            RedisNativeClient client = this.pool.GetRedisClient(key);

            return((client == null) ? 0L : client.LRem(key, removeNoOfMatches, UTF8String.ToBytes(value)));
        }
예제 #15
0
        public long PrependItemToList(string listId, string value)
        {
            RedisNativeClient client = this.pool.GetRedisClient(listId);

            return((client == null) ? 0L : client.LPush(listId, UTF8String.ToBytes(value)));
        }