// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using StackExchange.Redis;
namespace EpicGames.Redis
{
///
/// Represents a typed Redis set with a given key
///
///
public record struct RedisSet(IDatabaseAsync Database, RedisSetKey Key);
///
/// Extension methods for sets
///
public static class RedisSetExtensions
{
#region Conditions
///
public static Condition SetContains(this RedisSet target, TElement value)
=> target.Key.SetContains(value);
///
public static Condition SetLengthEqual(this RedisSet target, long length)
=> target.Key.SetLengthEqual(length);
///
public static Condition SetLengthGreaterThan(this RedisSet target, long length)
=> target.Key.SetLengthGreaterThan(length);
///
public static Condition SetLengthLessThan(this RedisSet target, long length)
=> target.Key.SetLengthLessThan(length);
///
public static Condition SetNotContains(this RedisSet target, TElement value)
=> target.Key.SetNotContains(value);
#endregion
#region SetAddAsync
///
public static Task AddAsync(this RedisSet target, TElement item, CommandFlags flags = CommandFlags.None)
=> target.Database.SetAddAsync(target.Key, item, flags);
///
public static Task AddAsync(this RedisSet target, TElement[] values, CommandFlags flags = CommandFlags.None)
=> target.Database.SetAddAsync(target.Key, values, flags);
#endregion
#region SetContainsAsync
///
public static Task ContainsAsync(this RedisSet target, TElement value, CommandFlags flags = CommandFlags.None)
=> target.Database.SetContainsAsync(target.Key, value, flags);
#endregion
#region SetLengthAsync
///
public static Task LengthAsync(this RedisSet target, CommandFlags flags = CommandFlags.None)
=> target.Database.SetLengthAsync(target.Key, flags);
#endregion
#region SetMembersAsync
///
public static Task MembersAsync(this RedisSet target, CommandFlags flags = CommandFlags.None)
=> target.Database.SetMembersAsync(target.Key, flags);
#endregion
#region SetPopAsync
///
public static Task PopAsync(this RedisSet target, CommandFlags flags = CommandFlags.None)
=> target.Database.SetPopAsync(target.Key, flags);
///
public static Task PopAsync(this RedisSet target, long count, CommandFlags flags = CommandFlags.None)
=> target.Database.SetPopAsync(target.Key, count, flags);
#endregion
#region SetRandomMemberAsync
///
public static Task RandomMemberAsync(this RedisSet target, CommandFlags flags = CommandFlags.None)
=> target.Database.SetRandomMemberAsync(target.Key, flags);
#endregion
#region SetRemoveAsync
///
public static Task RemoveAsync(this RedisSet target, TElement item, CommandFlags flags = CommandFlags.None)
=> target.Database.SetRemoveAsync(target.Key, item, flags);
///
public static Task RemoveAsync(this RedisSet target, TElement[] values, CommandFlags flags = CommandFlags.None)
=> target.Database.SetRemoveAsync(target.Key, values, flags);
#endregion
#region SetScanAsync
///
public static IAsyncEnumerable ScanAsync(this RedisSet target, RedisValue pattern = default, int pageSize = 250, long cursor = 0, int pageOffset = 0, CommandFlags flags = CommandFlags.None)
=> target.Database.SetScanAsync(target.Key, pattern, pageSize, cursor, pageOffset, flags);
#endregion
}
}