Documentation ¶
Overview ¶
Example ¶
ctx := context.Background() c := redigo.New(&redis.Options{}, redigo.NewGobEncoder()) err := c.Ping(ctx) if err != nil { log.Fatalln(err) } err = c.Set(ctx, "my-key", "hello", redigo.Options{ Expiration: time.Second * 100, Tags: []string{"my-tag"}, }) if err != nil { log.Fatalln(err) } var val string err = c.Get(ctx, "my-key", &val) if err != nil { log.Fatalln(err) } err = c.Delete(ctx, "my-key") if err != nil { log.Fatalln(err) }
Output:
Index ¶
- type Cache
- func (c *Cache) Close() error
- func (c *Cache) Delete(ctx context.Context, key string) error
- func (c *Cache) Flush(ctx context.Context)
- func (c *Cache) Get(ctx context.Context, key string, v any) error
- func (c *Cache) Invalidate(ctx context.Context, tags []string)
- func (c *Cache) Ping(ctx context.Context) error
- func (c *Cache) Set(ctx context.Context, key string, value any, options Options) error
- type Encoder
- type Options
- type Store
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache defines the methods for interacting with the cache layer.
func (*Cache) Get ¶
Get retrieves a specific item from the cache by key. Values are automatically marshalled for use with Redis.
func (*Cache) Invalidate ¶
Invalidate removes items from the cache from the tags passed.
type Encoder ¶
Encoder defines methods for encoding and decoding buffers into the cache store.
func NewGoJSONEncoder ¶ added in v0.0.2
func NewGoJSONEncoder() Encoder
NewGoJSONEncoder returns a new Go JSON encoder for RediGo.
func NewGobEncoder ¶
func NewGobEncoder() Encoder
NewGobEncoder returns a new Gob encoder for RediGo.
func NewJSONEncoder ¶
func NewJSONEncoder() Encoder
NewJSONEncoder returns a new Gob encoder for RediGo.
func NewMessagePackEncoder ¶ added in v0.0.2
func NewMessagePackEncoder() Encoder
NewMessagePackEncoder returns a new Message Pack encoder for RediGo.
type Options ¶
type Options struct { // Expiration allows to specify a global expiration // time hen setting a value. Expiration time.Duration // Tags allows specifying associated tags to the // current value. Tags []string }
Options represents the cache store available options when using Set().
type Store ¶
type Store interface { // Ping pings the Redis cache to ensure its alive. Ping(context.Context) error // Get retrieves a specific item from the cache by key. Values are // automatically marshalled for use with Redis. Get(context.Context, string, any) error // Set stores a singular item in memory by key, value // and options (tags and expiration time). Values are automatically // marshalled for use with Redis & Memcache. Set(context.Context, string, any, Options) error // Delete removes a singular item from the cache by // a specific key. Delete(context.Context, string) error // Invalidate removes items from the cache via the tags passed. Invalidate(context.Context, []string) // Flush removes all items from the cache. Flush(context.Context) // Closer closes the client, releasing any open resources. io.Closer }
Store defines methods for interacting with the caching system.