mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2026-11-01 02:31:39 +08:00
24 lines
569 B
Go
24 lines
569 B
Go
package cache
|
|
|
|
// RedisCacheConfig Redis连接配置
|
|
type RedisCacheConfig struct {
|
|
Host string
|
|
Port int
|
|
Password string
|
|
DB int
|
|
}
|
|
|
|
// NewCacheStore 根据cacheType创建缓存实例
|
|
// cacheType: "memory"(默认)| "redis"
|
|
// 当 cacheType 为 "redis" 但 Redis 不可达时返回 error
|
|
func NewCacheStore(cacheType string, redisCfg *RedisCacheConfig) (CacheStore, error) {
|
|
if cacheType == "redis" && redisCfg != nil {
|
|
rc, err := NewRedisCache(redisCfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return rc, nil
|
|
}
|
|
return InitWafCache(), nil
|
|
}
|