Documentation
¶
Index ¶
- func ExampleAddToBloomFilter()
- func ExampleRedisBloomFilter()
- type LegacyBloomBatchChecker
- type RedisBloomFilterChecker
- func (r *RedisBloomFilterChecker) AddToBloomFilter(ctx context.Context, key string, itemID string, ttl int) error
- func (r *RedisBloomFilterChecker) BatchAddToBloomFilter(ctx context.Context, key string, itemIDs []string, ttl int) error
- func (r *RedisBloomFilterChecker) CheckInBloomFilter(ctx context.Context, key string, itemID string) (bool, error)
- func (r *RedisBloomFilterChecker) ClearCache()
- func (r *RedisBloomFilterChecker) ClearCacheKey(key string)
- type RedisStore
- func (r *RedisStore) BatchGet(ctx context.Context, keys []string) (map[string][]byte, error)
- func (r *RedisStore) BatchSet(ctx context.Context, kvs map[string][]byte, ttl ...int) error
- func (r *RedisStore) Close(ctx context.Context) error
- func (r *RedisStore) Delete(ctx context.Context, key string) error
- func (r *RedisStore) Get(ctx context.Context, key string) ([]byte, error)
- func (r *RedisStore) GetClient() *redis.Client
- func (r *RedisStore) HGet(ctx context.Context, key, field string) ([]byte, error)
- func (r *RedisStore) HGetAll(ctx context.Context, key string) (map[string][]byte, error)
- func (r *RedisStore) HSet(ctx context.Context, key, field string, value []byte) error
- func (r *RedisStore) Name() string
- func (r *RedisStore) Set(ctx context.Context, key string, value []byte, ttl ...int) error
- func (r *RedisStore) ZAdd(ctx context.Context, key string, score float64, member string) error
- func (r *RedisStore) ZRange(ctx context.Context, key string, start, stop int64) ([]string, error)
- func (r *RedisStore) ZRangeWithScores(ctx context.Context, key string, start, stop int64) ([]core.ScoredMember, error)
- func (r *RedisStore) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) ([]core.ScoredMember, error)
- func (r *RedisStore) ZScore(ctx context.Context, key string, member string) (float64, error)
- type TairBloomBatchChecker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExampleAddToBloomFilter ¶
func ExampleAddToBloomFilter()
ExampleAddToBloomFilter 展示如何将曝光数据添加到布隆过滤器
func ExampleRedisBloomFilter ¶
func ExampleRedisBloomFilter()
ExampleRedisBloomFilter 展示如何使用 Redis + bits-and-blooms/bloom 实现布隆过滤器
Types ¶
type LegacyBloomBatchChecker ¶
type LegacyBloomBatchChecker struct {
Client *redis.Client
Capacity uint
FalsePositiveRate float64
}
LegacyBloomBatchChecker 适配 legacy STRING bloom 方案。 读取 rolling slot + :all 到内存后,对整批 item 做纯内存判定。
func NewLegacyBloomBatchChecker ¶
func NewLegacyBloomBatchChecker(client *redis.Client, capacity uint, falsePositiveRate float64) *LegacyBloomBatchChecker
type RedisBloomFilterChecker ¶
type RedisBloomFilterChecker struct {
// contains filtered or unexported fields
}
func NewRedisBloomFilterChecker ¶
func NewRedisBloomFilterChecker(store *RedisStore, capacity uint, falsePositiveRate float64) *RedisBloomFilterChecker
NewRedisBloomFilterChecker 创建一个新的 Redis 布隆过滤器检查器。
参数:
- store: RedisStore 实例
- capacity: 预期容量(元素数量),例如 1000000 表示预期存储 100 万个元素
- falsePositiveRate: 期望的误判率,例如 0.01 表示 1% 的误判率
示例:
store, _ := NewRedisStore("localhost:6379", 0)
checker := NewRedisBloomFilterChecker(store, 1000000, 0.01)
func NewRedisBloomFilterCheckerWithClient ¶
func NewRedisBloomFilterCheckerWithClient(client *redis.Client, capacity uint, falsePositiveRate float64) *RedisBloomFilterChecker
NewRedisBloomFilterCheckerWithClient 使用 *redis.Client 创建布隆过滤器检查器(高级用法)。 如果已有 *redis.Client 实例,可以使用此方法。
func (*RedisBloomFilterChecker) AddToBloomFilter ¶
func (r *RedisBloomFilterChecker) AddToBloomFilter(ctx context.Context, key string, itemID string, ttl int) error
AddToBloomFilter 将 itemID 添加到指定 key 的布隆过滤器中。 这是一个辅助方法,用于数据写入场景(例如曝光数据收集)。
参数:
- ctx: 上下文
- key: 布隆过滤器的 Redis key
- itemID: 要添加的物品 ID
- ttl: 过期时间(秒),0 表示不过期
返回:
- error: 错误信息
func (*RedisBloomFilterChecker) BatchAddToBloomFilter ¶
func (r *RedisBloomFilterChecker) BatchAddToBloomFilter(ctx context.Context, key string, itemIDs []string, ttl int) error
BatchAddToBloomFilter 批量将 itemIDs 添加到指定 key 的布隆过滤器中。 这是一个辅助方法,用于批量数据写入场景。
参数:
- ctx: 上下文
- key: 布隆过滤器的 Redis key
- itemIDs: 要添加的物品 ID 列表
- ttl: 过期时间(秒),0 表示不过期
返回:
- error: 错误信息
func (*RedisBloomFilterChecker) CheckInBloomFilter ¶
func (r *RedisBloomFilterChecker) CheckInBloomFilter(ctx context.Context, key string, itemID string) (bool, error)
CheckInBloomFilter 检查 itemID 是否在指定 key 的布隆过滤器中。 实现了 filter.BloomFilterChecker 接口。
参数:
- ctx: 上下文
- key: 布隆过滤器的 Redis key,格式为 {keyPrefix}:bloom:{userID}:{date}
- itemID: 要检查的物品 ID
返回:
- bool: true 表示可能在布隆过滤器中(存在误判可能),false 表示一定不在
- error: 错误信息
func (*RedisBloomFilterChecker) ClearCache ¶
func (r *RedisBloomFilterChecker) ClearCache()
ClearCache 清除本地缓存。 当需要强制从 Redis 重新加载布隆过滤器时使用。
func (*RedisBloomFilterChecker) ClearCacheKey ¶
func (r *RedisBloomFilterChecker) ClearCacheKey(key string)
ClearCacheKey 清除指定 key 的本地缓存。
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore 是 Redis 实现的 KeyValueStore,支持所有 Redis 数据结构操作。 生产环境常用,支持持久化、集群、哨兵等。
注意:此实现位于扩展包中,需要单独引入:
go get github.com/rushteam/reckit/ext/store/redis
func NewRedisStore ¶
func NewRedisStore(addr string, db int) (*RedisStore, error)
NewRedisStore 创建一个新的 Redis 存储实例。
func (*RedisStore) GetClient ¶
func (r *RedisStore) GetClient() *redis.Client
GetClient 返回内部的 Redis 客户端(用于高级用法,如布隆过滤器)。 注意:此方法仅用于需要直接访问 Redis 客户端的场景。
func (*RedisStore) Name ¶
func (r *RedisStore) Name() string
func (*RedisStore) ZRangeWithScores ¶
func (r *RedisStore) ZRangeWithScores(ctx context.Context, key string, start, stop int64) ([]core.ScoredMember, error)
func (*RedisStore) ZRevRangeWithScores ¶
func (r *RedisStore) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) ([]core.ScoredMember, error)
type TairBloomBatchChecker ¶
TairBloomBatchChecker 适配 TairBloom BF.MEXISTS 方案。 通过 pipeline 一次 round-trip 完成多 slot 检查。
func NewTairBloomBatchChecker ¶
func NewTairBloomBatchChecker(client *redis.Client) *TairBloomBatchChecker