Ejemplo n.º 1
0
        public long ListRightPush <T>(string key, List <T> value, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(ExecuteCommand(ConnectTypeEnum.Write, connectionName, (db) =>
            {
                if (value != null)
                {
                    return 0;
                }
                RedisValue[] values = new RedisValue[value.Count];
                for (int i = 0; i < value.Count; i++)
                {
                    if (serializer != null)
                    {
                        values[i] = serializer.Serializer(value[i]);
                    }
                    else
                    {
                        values[i] = redisSerializer.Serializer(value[i]);
                    }
                }
                return db.ListRightPush(key, values, CommandFlags.None);
            }));
        }
        public async Task <bool> HashSetAsync <T>(string hashId, string key, T value, OverWrittenTypeDenum isAlways, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(await ExecuteCommand(ConnectTypeEnum.Write, connectionName, async (db) =>
            {
                When when = When.Always;
                switch (isAlways)
                {
                case OverWrittenTypeDenum.Always:
                    when = When.Always;
                    break;

                case OverWrittenTypeDenum.Exists:
                    when = When.Exists;
                    break;

                case OverWrittenTypeDenum.NotExists:
                    when = When.NotExists;
                    break;
                }

                if (serializer != null)
                {
                    return await db.HashSetAsync(hashId, key, serializer.Serializer(value), when);
                }
                return await db.HashSetAsync(hashId, key, redisSerializer.Serializer(value), when);
            }));
        }
        public async Task <bool> HashSetAsync <T>(string hashId, string key, T value, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(await ExecuteCommand(ConnectTypeEnum.Write, connectionName, async (db) =>
            {
                if (serializer != null)
                {
                    return await db.HashSetAsync(hashId, key, serializer.Serializer(value));
                }
                return await db.HashSetAsync(hashId, key, redisSerializer.Serializer(value));
            }));
        }
Ejemplo n.º 4
0
        public long ListRightPushWhenNoExists <T>(string key, T value, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(ExecuteCommand(ConnectTypeEnum.Write, connectionName, (db) =>
            {
                if (serializer != null)
                {
                    return db.ListRightPush(key, serializer.Serializer(value), When.Always, CommandFlags.None);
                }
                return db.ListRightPush(key, redisSerializer.Serializer(value), When.Always, CommandFlags.None);
            }));
        }
Ejemplo n.º 5
0
        public long ListRemove <T>(string key, T value, long removecount, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(ExecuteCommand(ConnectTypeEnum.Write, connectionName, (db) =>
            {
                if (serializer != null)
                {
                    return db.ListRemove(key, serializer.Serializer(value), removecount);
                }
                return db.ListRemove(key, redisSerializer.Serializer(value), removecount);
            }));
        }
Ejemplo n.º 6
0
        public long ListInsertAfter <T>(string key, T value, string insertvalue, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(ExecuteCommand(ConnectTypeEnum.Write, connectionName, (db) =>
            {
                if (serializer != null)
                {
                    return db.ListInsertAfter(key, serializer.Serializer(value), insertvalue);
                }
                return db.ListInsertAfter(key, redisSerializer.Serializer(value), insertvalue);
            }));
        }
        public async Task ListSetByIndexAsync <T>(string key, long index, T value, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            await ExecuteCommand(ConnectTypeEnum.Write, connectionName, async (db) =>
            {
                if (serializer != null)
                {
                    await db.ListSetByIndexAsync(key, index, serializer.Serializer(value));
                }
                await db.ListSetByIndexAsync(key, index, redisSerializer.Serializer(value));
            });
        }
Ejemplo n.º 8
0
        public async Task <bool> LockTakeAsync <T>(string key, T value, int seconds, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(await ExecuteCommand(ConnectTypeEnum.Write, connectionName, async (db) =>
            {
                if (serializer != null)
                {
                    return await db.LockTakeAsync(key, serializer.Serializer(value), TimeSpan.FromSeconds(seconds));
                }
                return await db.LockTakeAsync(key, redisSerializer.Serializer(value), TimeSpan.FromSeconds(seconds));
            }));
        }
Ejemplo n.º 9
0
        public bool SortedRemove <T>(string key, T value, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(ExecuteCommand(ConnectTypeEnum.Write, connectionName, (db) =>
            {
                if (serializer != null)
                {
                    return db.SortedSetRemove(key, serializer.Serializer(value));
                }
                return db.SortedSetRemove(key, redisSerializer.Serializer(value));
            }));
        }
Ejemplo n.º 10
0
        public bool HashSet <T>(string hashId, string key, T value, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(ExecuteCommand(ConnectTypeEnum.Write, connectionName, (db) =>
            {
                if (serializer != null)
                {
                    return db.HashSet(hashId, key, serializer.Serializer(value));
                }
                return db.HashSet(hashId, key, redisSerializer.Serializer(value));
            }));
        }
        public async Task <long> ListRightPushWhenExistsAsync <T>(string key, T value, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(await ExecuteCommand(ConnectTypeEnum.Write, connectionName, async (db) =>
            {
                if (serializer != null)
                {
                    return await db.ListRightPushAsync(key, serializer.Serializer(value), When.Exists, CommandFlags.None);
                }
                return await db.ListRightPushAsync(key, redisSerializer.Serializer(value), When.Exists, CommandFlags.None);
            }));
        }
        public async Task <bool> SortedAddAsync <T>(string key, T value, double score, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(await ExecuteCommand(ConnectTypeEnum.Write, connectionName, async (db) =>
            {
                if (serializer != null)
                {
                    return await db.SortedSetAddAsync(key, serializer.Serializer(value), score);
                }
                return await db.SortedSetAddAsync(key, redisSerializer.Serializer(value), score);
            }));
        }
        public async Task <long> ListRemoveAsync <T>(string key, T value, long removecount, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(await ExecuteCommand(ConnectTypeEnum.Write, connectionName, async (db) =>
            {
                if (serializer != null)
                {
                    return await db.ListRemoveAsync(key, serializer.Serializer(value), removecount);
                }
                return await db.ListRemoveAsync(key, redisSerializer.Serializer(value), removecount);
            }));
        }
Ejemplo n.º 14
0
        public bool LockExtend <T>(string key, T value, int seconds, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(ExecuteCommand(ConnectTypeEnum.Write, connectionName, (db) =>
            {
                if (serializer != null)
                {
                    return db.LockExtend(key, serializer.Serializer(value), TimeSpan.FromSeconds(seconds));
                }
                return db.LockExtend(key, redisSerializer.Serializer(value), TimeSpan.FromSeconds(seconds));
            }));
        }
        public async Task <long?> SortedZrankAsync <T>(string key, T value, int orderby = 0, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(await ExecuteCommand(ConnectTypeEnum.Read, connectionName, async (db) =>
            {
                Order o = orderby == 1 ? Order.Descending : Order.Ascending;
                if (serializer != null)
                {
                    return await db.SortedSetRankAsync(key, serializer.Serializer(value), o);
                }
                return await db.SortedSetRankAsync(key, redisSerializer.Serializer(value), o);
            }));
        }
Ejemplo n.º 16
0
        public void ListSetByIndex <T>(string key, long index, T value, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            ExecuteCommand(ConnectTypeEnum.Write, connectionName, (db) =>
            {
                if (serializer != null)
                {
                    db.ListSetByIndex(key, index, serializer.Serializer(value));
                }
                else
                {
                    db.ListSetByIndex(key, index, redisSerializer.Serializer(value));
                }
            });
        }
Ejemplo n.º 17
0
        public long SortedRemove <T>(string key, IList <T> values, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(ExecuteCommand(ConnectTypeEnum.Write, connectionName, (db) =>
            {
                List <RedisValue> listValues = new List <RedisValue>();
                foreach (var val in values)
                {
                    if (serializer != null)
                    {
                        listValues.Add(serializer.Serializer(val));
                    }
                    listValues.Add(redisSerializer.Serializer(val));
                }

                return db.SortedSetRemove(key, listValues.ToArray());
            }));
        }
        public async Task <long> ListLeftPushAsync <T>(string key, List <T> value, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(await ExecuteCommand(ConnectTypeEnum.Write, connectionName, async (db) =>
            {
                RedisValue[] values = new RedisValue[value.Count];
                for (int i = 0; i < value.Count; i++)
                {
                    if (serializer != null)
                    {
                        values[i] = serializer.Serializer(value[i]);
                    }
                    else
                    {
                        values[i] = redisSerializer.Serializer(value[i]);
                    }
                }
                return await db.ListLeftPushAsync(key, values, CommandFlags.None);
            }));
        }
        public async Task <long> SortedAddAsync <T>(string key, Dictionary <T, double> values, string connectionName = null, IRedisSerializer serializer = null)
        {
            RedisThrow.NullSerializer(redisSerializer, serializer);

            return(await ExecuteCommand(ConnectTypeEnum.Write, connectionName, async (db) =>
            {
                List <SortedSetEntry> sortedEntry = new List <SortedSetEntry>();
                foreach (var keyvalue in values)
                {
                    if (serializer != null)
                    {
                        var entry = new SortedSetEntry(serializer.Serializer(keyvalue.Key), keyvalue.Value);
                        sortedEntry.Add(entry);
                    }
                    else
                    {
                        var entry = new SortedSetEntry(redisSerializer.Serializer(keyvalue.Key), keyvalue.Value);
                        sortedEntry.Add(entry);
                    }
                }
                return await db.SortedSetAddAsync(key, sortedEntry.ToArray());
            }));
        }