redis.go 681 B

1234567891011121314151617181920212223242526272829303132
  1. package cache
  2. import (
  3. "time"
  4. "github.com/go-redis/redis/v7"
  5. "github.com/matchstalk/go-admin-core/cache"
  6. "github.com/matchstalk/redisqueue"
  7. )
  8. var RedisAdapter Adapter
  9. func InitRedis() error {
  10. RedisAdapter = &cache.Redis{
  11. ConnectOption: &redis.Options{
  12. Addr: "127.0.0.1:6379",
  13. },
  14. ConsumerOptions: &redisqueue.ConsumerOptions{
  15. VisibilityTimeout: 60 * time.Second,
  16. BlockingTimeout: 5 * time.Second,
  17. ReclaimInterval: 1 * time.Second,
  18. BufferSize: 100,
  19. Concurrency: 10,
  20. },
  21. ProducerOptions: &redisqueue.ProducerOptions{
  22. StreamMaxLength: 100,
  23. ApproximateMaxLength: true,
  24. },
  25. }
  26. err := RedisAdapter.Connect()
  27. return err
  28. }