Documentation
¶
Overview ¶
Application scenarios: - Multi-instance shared captcha store backed by Redis. - Graceful automatic fallback to in-memory store when Redis is unavailable. - High-availability verification with timeout control.
适用场景: - 基于 Redis 的多实例共享验证码存储。 - Redis 不可用时自动优雅降级为单机内存存储。 - 带超时控制的高可用验证码校验。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*RedisCaptchaStore)
Option configures RedisCaptchaStore options.
func WithExpiration ¶
WithExpiration configures the captcha TTL.
func WithFallback ¶
func WithFallback(fallback base64Captcha.Store) Option
WithFallback configures the fallback store when Redis is unavailable or errors.
func WithPrefix ¶
WithPrefix configures the Redis key prefix for captcha entries.
func WithTimeout ¶
WithTimeout configures the timeout for Redis operations.
type RedisCaptchaStore ¶
type RedisCaptchaStore struct {
// contains filtered or unexported fields
}
RedisCaptchaStore implements base64Captcha.Store and securitycontract.CaptchaStore backed by Redis, with automatic graceful fallback to an in-memory store.
func NewRedisCaptchaStore ¶
func NewRedisCaptchaStore(redis datacontract.Redis, opts ...Option) *RedisCaptchaStore
NewRedisCaptchaStore creates a captcha store instance. If redis is nil, it automatically delegates to base64Captcha.DefaultMemStore.
func (*RedisCaptchaStore) Get ¶
func (s *RedisCaptchaStore) Get(id string, clear bool) string
Get retrieves the captcha value by id, optionally clearing it.