NewRedisRefreshTokenStore creates a new Redis-based refresh token store with client-side caching
(config *RedisConfig)
| 62 | |
| 63 | // NewRedisRefreshTokenStore creates a new Redis-based refresh token store with client-side caching |
| 64 | func NewRedisRefreshTokenStore(config *RedisConfig) (*RedisRefreshTokenStore, error) { |
| 65 | if config == nil { |
| 66 | config = DefaultRedisConfig() |
| 67 | } |
| 68 | |
| 69 | // Build Redis client options |
| 70 | clientOpt := rueidis.ClientOption{ |
| 71 | InitAddress: []string{config.Addr}, |
| 72 | Password: config.Password, |
| 73 | SelectDB: config.DB, |
| 74 | |
| 75 | // TLS configuration |
| 76 | TLSConfig: config.TLSConfig, |
| 77 | |
| 78 | // Connection configuration |
| 79 | ConnWriteTimeout: 10 * time.Second, |
| 80 | |
| 81 | // Client-side cache configuration |
| 82 | CacheSizeEachConn: config.CacheSize, |
| 83 | DisableCache: false, |
| 84 | } |
| 85 | |
| 86 | // Create Redis client with client-side caching enabled |
| 87 | client, err := rueidis.NewClient(clientOpt) |
| 88 | if err != nil { |
| 89 | return nil, fmt.Errorf("failed to create Redis client: %w", err) |
| 90 | } |
| 91 | |
| 92 | // Test connection |
| 93 | ctx := context.Background() |
| 94 | if err := client.Do(ctx, client.B().Ping().Build()).Error(); err != nil { |
| 95 | client.Close() |
| 96 | return nil, fmt.Errorf("failed to connect to Redis: %w", err) |
| 97 | } |
| 98 | |
| 99 | return &RedisRefreshTokenStore{ |
| 100 | client: client, |
| 101 | prefix: config.KeyPrefix, |
| 102 | ctx: ctx, |
| 103 | cacheTTL: config.CacheTTL, |
| 104 | }, nil |
| 105 | } |
| 106 | |
| 107 | // Close closes the Redis client connection |
| 108 | func (s *RedisRefreshTokenStore) Close() error { |
searching dependent graphs…