namespace HoneyBox.Core.Interfaces;

/// <summary>
/// Redis服务接口 - 提供更细粒度的Redis操作
/// </summary>
public interface IRedisService
{
    /// <summary>
    /// 获取字符串值
    /// </summary>
    Task<string?> GetStringAsync(string key);

    /// <summary>
    /// 设置字符串值
    /// </summary>
    Task SetStringAsync(string key, string value, TimeSpan? expiry = null);

    /// <summary>
    /// 删除键
    /// </summary>
    Task DeleteAsync(string key);

    /// <summary>
    /// 检查键是否存在
    /// </summary>
    Task<bool> ExistsAsync(string key);

    /// <summary>
    /// 设置键的过期时间
    /// </summary>
    Task<bool> ExpireAsync(string key, TimeSpan expiry);

    /// <summary>
    /// 获取键的剩余过期时间
    /// </summary>
    Task<TimeSpan?> GetTtlAsync(string key);

    /// <summary>
    /// 尝试获取分布式锁
    /// </summary>
    Task<bool> TryAcquireLockAsync(string key, string value, TimeSpan expiry);

    /// <summary>
    /// 释放分布式锁
    /// </summary>
    Task<bool> ReleaseLockAsync(string key, string value);

    /// <summary>
    /// 根据模式获取所有匹配的键
    /// </summary>
    /// <param name="pattern">匹配模式，如 "post_order:*"</param>
    /// <returns>匹配的键列表</returns>
    Task<IEnumerable<string>> GetKeysAsync(string pattern);
}
