gredis_adapter.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gredis
  7. import (
  8. "context"
  9. "github.com/gogf/gf/v2/container/gvar"
  10. )
  11. // Adapter is an interface for universal redis operations.
  12. type Adapter interface {
  13. // Conn retrieves and returns a connection object for continuous operations.
  14. // Note that you should call Close function manually if you do not use this connection any further.
  15. Conn(ctx context.Context) (conn Conn, err error)
  16. // Close closes current redis client, closes its connection pool and releases all its related resources.
  17. Close(ctx context.Context) (err error)
  18. }
  19. // Conn is an interface of a connection from universal redis client.
  20. type Conn interface {
  21. // Do send a command to the server and returns the received reply.
  22. // It uses json.Marshal for struct/slice/map type values before committing them to redis.
  23. Do(ctx context.Context, command string, args ...interface{}) (result *gvar.Var, err error)
  24. // Receive receives a single reply as gvar.Var from the Redis server.
  25. Receive(ctx context.Context) (result *gvar.Var, err error)
  26. // Close puts the connection back to connection pool.
  27. Close(ctx context.Context) (err error)
  28. }