redis_generic.go 1005 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package backends
  2. import (
  3. "net"
  4. "time"
  5. )
  6. func init() {
  7. RedisDialer = func(network, address string, options ...RedisDialOption) (RedisConn, error) {
  8. return new(RedisMockConn), nil
  9. }
  10. }
  11. // RedisConn interface provides a generic way to access Redis via drivers
  12. type RedisConn interface {
  13. Close() error
  14. Do(commandName string, args ...interface{}) (reply interface{}, err error)
  15. }
  16. type RedisMockConn struct{}
  17. func (m *RedisMockConn) Close() error {
  18. return nil
  19. }
  20. func (m *RedisMockConn) Do(commandName string, args ...interface{}) (reply interface{}, err error) {
  21. Log().Info("redis mock driver command: ", commandName)
  22. return nil, nil
  23. }
  24. type dialOptions struct {
  25. readTimeout time.Duration
  26. writeTimeout time.Duration
  27. dial func(network, addr string) (net.Conn, error)
  28. db int
  29. password string
  30. }
  31. type RedisDialOption struct {
  32. f func(*dialOptions)
  33. }
  34. type redisDial func(network, address string, options ...RedisDialOption) (RedisConn, error)
  35. var RedisDialer redisDial