redis

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2020 License: MIT Imports: 3 Imported by: 0

README

Using the Redigo Backer

pool := &redigo.Pool{
  MaxActive: 10,
  MaxIdle:   5,
  Wait:      true,
  Dial: func() (redigo.Conn, error) {
    return redigo.DialURL("redis://localhost:6379")
  },
}

backer := redis.New(pool, "my-keyspace")

c, err := cache.NewClient(backer)
defer c.Close()

err = c.Set("key", "value")

var out string
err = c.Get(key, &out)

You must instantiate the backer and pass it to the cache.NewClient function. From there, you never need to touch the backer again. The cache client will take care of managing state, shutdown, etc of the backer. The pool, however, will remain your responsibility. The backer will *not close the redis pool.

Keyspace

In the backer New function, a keyspace was provided as the second argument. This keyspace allows us to run multiple distinct caches on the same redis server while avoiding collisions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(pool *redis.Pool, keyspace string) cache.Backer

New creates a redis-backed cache. It expects a fully initialized redis pool through which it will handle all operations.

Keyspace is the namespace under which our keys will live. This is to prevent multiple instances of this package from colliding.

Types

type Backer

type Backer struct {
	// contains filtered or unexported fields
}

func (*Backer) Close

func (r *Backer) Close()

Close is a no-op for this backer.

func (*Backer) Delete

func (r *Backer) Delete(key string) error

Delete deletes a value from redis using the DEL command.

func (*Backer) Exists

func (r *Backer) Exists(key string) (bool, error)

Exists checks if the key exists in redis using the EXISTS command.

func (*Backer) Get

func (r *Backer) Get(key string) ([]byte, bool, error)

Get gets a value from redis using the GET command.

func (*Backer) Health

func (r *Backer) Health() error

Health returns the current health status of the remote cache.

Possible return values are:

nil - no issues
non-nil error - error reported by the remote cache

func (*Backer) Set

func (r *Backer) Set(key string, value []byte) error

Set sets a value in redis using the SET command.

func (*Backer) SetExpires

func (r *Backer) SetExpires(key string, value []byte, ttl time.Duration) error

SetExpires sets a value in redis using the PSETEX command. The ttl value has millisecond precision.

func (*Backer) UpdateExpiration

func (r *Backer) UpdateExpiration(key string, ttl time.Duration) error

UpdateExpiration updates the expiration time on the key. The ttl value has millisecond precision.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL