Exemplo n.º 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));
        }
Exemplo n.º 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))));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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)));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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)));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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)));
        }
Exemplo n.º 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)));
        }
Exemplo n.º 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)));
        }
Exemplo n.º 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)));
        }