using OASystem.RedisRepository.CommonHelper;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OASystem.RedisRepository.RedisAsyncHelper
{
    /// 
    /// Redis异步操作类  List部分类
    /// 
    internal partial class RedisHelper //: IRedisHelper
    {
        //    _client.ListRightPopLeftPushAsync();
        //    _client.ListTrimAsync();
        #region List 写操作
        public async Task ListInsertAfterAsync(string key, string pivot, T value)
        {
            return await _client.ListInsertAfterAsync(key, pivot, SerializeHelper.Serialize(value));
        }
        public async Task ListInsertBeforeAsync(string key, string pivot, T value)
        {
            return await _client.ListInsertBeforeAsync(key, pivot, SerializeHelper.Serialize(value));
        }
        public async Task ListLeftPopAsync(string key)
        {
            return SerializeHelper.Deserialize(await _client.ListLeftPopAsync(key));
        }
        public async Task ListLeftPushAsync(string key, T value)
        {
            return await _client.ListLeftPushAsync(key, SerializeHelper.Serialize(value));
        }
        public async Task ListLeftMultiPushAsync(string key, List values)
        {
            return await _client.ListLeftPushAsync(key, SerializeHelper.Serialize(RedisInnerTypeHelper.GenericListToRedisValues(values)));
        }
        public async Task ListRemoveAsync(string key, T value, long count = 0L)
        {
            return await _client.ListRemoveAsync(key, SerializeHelper.Serialize(value), count);
        }
        public async Task ListRightPopAsync(string key)
        {
            return SerializeHelper.Deserialize(await _client.ListRightPopAsync(key));
        }
        public async Task ListRightPushAsync(string key, T value)
        {
            return await _client.ListRightPushAsync(key, SerializeHelper.Serialize(value));
        }
        public async Task ListRightMultiPushAsync(string key, List values)
        {
            return
                await
                    _client.ListRightPushAsync(key,
                        SerializeHelper.Serialize(RedisInnerTypeHelper.GenericListToRedisValues(values)));
        }
        public async Task ListSetByIndexAsync(string key, int index, T value)
        {
            await _client.ListSetByIndexAsync(key, index, SerializeHelper.Serialize(value));
        }
        public async Task ListTrimAsync(string key, long start, long stop)
        {
            await _client.ListTrimAsync(key, start, stop);
        }
        #endregion
        #region List 读操作
        public async Task ListGetByIndexAsync(string key, long index)
        {
            return SerializeHelper.Deserialize(await _client.ListGetByIndexAsync(key, index, CommandFlags.PreferSlave));
        }
        public async Task ListLengthAsync(string key)
        {
            return await _client.ListLengthAsync(key, CommandFlags.PreferSlave);
        }
        public async Task> ListRangeAsync(string key, long start = 0L, long stop = -1L)
        {
            return RedisInnerTypeHelper.RedisValuesToGenericList(await _client.ListRangeAsync(key, start, stop, CommandFlags.PreferSlave));
        }
        #endregion
    }
}