pubsubx.go 334 B

1234567891011121314151617
  1. package redisx
  2. import (
  3. "context"
  4. "github.com/redis/go-redis/v9"
  5. )
  6. // 发布订阅
  7. func Publish(ctx context.Context, channel string, msg interface{}) error {
  8. return getClient().Publish(ctx, channel, msg).Err()
  9. }
  10. func Subscribe(ctx context.Context, channel string) *redis.PubSub {
  11. return getClient().Subscribe(ctx, channel)
  12. }