Categorygithub.com/topfreegames/go-extensions-redis
modulepackage
4.0.1+incompatible
Repository: https://github.com/topfreegames/go-extensions-redis.git
Documentation: pkg.go.dev

# README

go-extensions-redis

This library provides interfaces and implementations for Redis clients and multiplexers. It also has a very tight relationship with go-redis in order to reuse it's signatures and return types.

Clients interfaces are Client and LockerClient. The last one guarantees that implementers are both Client and Locker.

Locker implementers must expose functions to lock access to keys, in order to prevent race conditions. The implementation provided, BaseClient, is for a LockerClient.

Mux is an interface implemented by BaseMux. It's purpose is to use multiple redis instances as shards where operations over a key consistently happen in the same instance during a time interval either set through a TTL or manually invalidated by calling Invalidate(Hash) error present in Mux.

BaseMux mappings are also stored and retrieved through a redis client.

BaseClient and BaseMux have open-tracing support and provide WithContext(context.Context) methods.

Contribution

If any changes are made to interfaces and/or new interfaces are added, check make mocks command and run it.

TODO:

  • Tests
    • BaseMux implements Mux?
    • BaseClient implements Client?
    • Tracing
    • ErrClient
  • Mocks
  • Docs
  • ErrClient Pipeliner?

# Packages

Package mocks is a generated GoMock package.

# Functions

No description provided by the author
NewClient creates a BaseClient instance with an underlying *goredis.Client and a *redislock.Client.
No description provided by the author
No description provided by the author

# Structs

BaseClient implements Client since it wraps a *goredis.Client and Locker for distributed locking it's WithContext calls WithContext in the underlying *goredis.Client and instruments opentracing support through go-redis middlewares.
BaseMux is an implementation of Mux where On and OnMany mappings are made to random clients if no existing mapping for `hash` is found.
ErrClient returns an error for each Client operation.
LockOptions define available settings for Locker.Obtain.
No description provided by the author

# Interfaces

Client is a minimal set of functions a redis client must implement.
No description provided by the author
No description provided by the author
LockerClient is a redis Client that has support for Locker operations in order to use distributed locking, for example.
Mux is the minimal set of functions a redis multiplexer must implement.

# Type aliases

Hash needs to be a SHORT and UNIQUE string in order for Mux.On to work.