redis

package module
v1.17.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 25 Imported by: 1

README

Redis

A redis driver for facades.Cache(), facades.Queue() and facades.Session() of Goravel.

Version

goravel/redis goravel/framework
v1.17.x v1.17.x
v1.4.* v1.16.*
v1.3.* v1.15.*
v1.2.* v1.14.*
v1.1.* v1.13.*
v1.0.* v1.12.*

Install

Run the command below in your project to install the package automatically:

./artisan package:install github.com/goravel/redis

Or check the setup file to install the package manually.

Testing

Run command below to run test:

go test ./...

Documentation

Index

Constants

View Source
const (
	BindingCache   = "goravel.redis.cache"
	BindingQueue   = "goravel.redis.queue"
	BindingSession = "goravel.redis.session"

	Name = "redis"
)

Variables

View Source
var (
	ErrRedisServiceProviderNotRegistered = errors.New("please register redis service provider").SetModule("Redis")
	ErrRedisStoreIsRequired              = errors.New("store is required").SetModule("Redis")
	ErrRedisConnectionIsRequired         = errors.New("connection is required").SetModule("Redis")
	ErrSessionDriverIsRequired           = errors.New("session driver is required").SetModule("Redis")
)

Functions

func GetClient added in v1.17.0

func GetClient(config config.Config, connection string) (redis.UniversalClient, error)

GetClient returns a Redis client for the specified connection name. It uses a cached instance if one already exists for the name, otherwise, it creates, caches, and returns a new one. It is thread-safe. Returns an error if the client cannot be created or configured correctly.

Types

type Cache added in v1.4.0

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

func NewCache added in v1.4.0

func NewCache(ctx context.Context, config config.Config, process process.Process, store string) (*Cache, error)

func (*Cache) Add added in v1.4.0

func (r *Cache) Add(key string, value any, t time.Duration) bool

Add Driver an item in the cache if the key does not exist.

func (*Cache) Decrement added in v1.4.0

func (r *Cache) Decrement(key string, value ...int64) (int64, error)

func (*Cache) Docker added in v1.4.0

func (r *Cache) Docker() (contractsdocker.CacheDriver, error)

func (*Cache) Flush added in v1.4.0

func (r *Cache) Flush() bool

Flush Remove all items from the cache.

func (*Cache) Forever added in v1.4.0

func (r *Cache) Forever(key string, value any) bool

Forever Driver an item in the cache indefinitely.

func (*Cache) Forget added in v1.4.0

func (r *Cache) Forget(key string) bool

Forget Remove an item from the cache.

func (*Cache) Get added in v1.4.0

func (r *Cache) Get(key string, def ...any) any

Get Retrieve an item from the cache by key.

func (*Cache) GetBool added in v1.4.0

func (r *Cache) GetBool(key string, def ...bool) bool

func (*Cache) GetInt added in v1.4.0

func (r *Cache) GetInt(key string, def ...int) int

func (*Cache) GetInt64 added in v1.4.0

func (r *Cache) GetInt64(key string, def ...int64) int64

func (*Cache) GetString added in v1.4.0

func (r *Cache) GetString(key string, def ...string) string

func (*Cache) Has added in v1.4.0

func (r *Cache) Has(key string) bool

Has Check an item exists in the cache.

func (*Cache) Increment added in v1.4.0

func (r *Cache) Increment(key string, value ...int64) (int64, error)

func (*Cache) Lock added in v1.4.0

func (r *Cache) Lock(key string, t ...time.Duration) contractscache.Lock

func (*Cache) Pull added in v1.4.0

func (r *Cache) Pull(key string, def ...any) any

Pull Retrieve an item from the cache and delete it.

func (*Cache) Put added in v1.4.0

func (r *Cache) Put(key string, value any, t time.Duration) error

Put Driver an item in the cache for a given time.

func (*Cache) Remember added in v1.4.0

func (r *Cache) Remember(key string, seconds time.Duration, callback func() (any, error)) (any, error)

Remember Get an item from the cache, or execute the given Closure and store the result.

func (*Cache) RememberForever added in v1.4.0

func (r *Cache) RememberForever(key string, callback func() (any, error)) (any, error)

RememberForever Get an item from the cache, or execute the given Closure and store the result forever.

func (*Cache) WithContext added in v1.4.0

func (r *Cache) WithContext(ctx context.Context) contractscache.Driver

type Docker added in v1.4.0

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

func NewDocker added in v1.4.0

func NewDocker(config contractsconfig.Config, process contractsprocess.Process, store string) (*Docker, error)

func (*Docker) Build added in v1.4.0

func (r *Docker) Build() error

func (*Docker) Config added in v1.4.0

func (r *Docker) Config() contractsdocker.CacheConfig

func (*Docker) Fresh added in v1.4.0

func (r *Docker) Fresh() error

func (*Docker) Image added in v1.4.0

func (r *Docker) Image(image contractsdocker.Image)

func (*Docker) Ready added in v1.4.0

func (r *Docker) Ready() error

func (*Docker) Reuse added in v1.4.0

func (r *Docker) Reuse(containerID string, port int) error

func (*Docker) Shutdown added in v1.4.0

func (r *Docker) Shutdown() error

type Job added in v1.4.0

type Job struct {
	Signature string               `json:"signature"`
	Args      []contractsqueue.Arg `json:"args"`
	Delay     *time.Time           `json:"delay"`
}

type JobRecord added in v1.4.0

type JobRecord struct {
	Playload   string           `json:"playload"`
	Attempts   int              `json:"attempts"`
	ReservedAt *carbon.DateTime `json:"reserved_at"`
}

func (*JobRecord) Increment added in v1.4.0

func (r *JobRecord) Increment() int

func (*JobRecord) Touch added in v1.4.0

func (r *JobRecord) Touch() *carbon.DateTime

type Queue added in v1.4.0

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

func NewQueue added in v1.4.0

func NewQueue(ctx context.Context, config config.Config, queue contractsqueue.Queue, json foundation.Json, connection string) (*Queue, error)

func (*Queue) Driver added in v1.4.0

func (r *Queue) Driver() string

func (*Queue) Later added in v1.4.0

func (r *Queue) Later(delay time.Time, task contractsqueue.Task, queue string) error

func (*Queue) Pop added in v1.4.0

func (r *Queue) Pop(queue string) (contractsqueue.ReservedJob, error)

func (*Queue) Push added in v1.4.0

func (r *Queue) Push(task contractsqueue.Task, queue string) error

type QueueKey added in v1.4.0

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

func NewQueueKey added in v1.4.0

func NewQueueKey(appName string, connection string) *QueueKey

func (*QueueKey) Delayed added in v1.4.0

func (r *QueueKey) Delayed(queue string) string

func (*QueueKey) Queue added in v1.4.0

func (r *QueueKey) Queue(queue string) string

func (*QueueKey) Reserved added in v1.4.0

func (r *QueueKey) Reserved(queue string) string

type ReservedJob added in v1.4.0

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

func NewReservedJob added in v1.4.0

func NewReservedJob(ctx context.Context, client redis.UniversalClient, jobRecord JobRecord, jobStorer contractsqueue.JobStorer, json contractsfoundation.Json, reservedQueueKey string) (*ReservedJob, error)

func (*ReservedJob) Delete added in v1.4.0

func (r *ReservedJob) Delete() error

func (*ReservedJob) Task added in v1.4.0

func (r *ReservedJob) Task() contractsqueue.Task

type ServiceProvider

type ServiceProvider struct {
}

func (*ServiceProvider) Boot

func (r *ServiceProvider) Boot(app foundation.Application)

func (*ServiceProvider) Register

func (r *ServiceProvider) Register(app foundation.Application)

func (*ServiceProvider) Relationship added in v1.4.0

func (r *ServiceProvider) Relationship() binding.Relationship

type Session added in v1.4.0

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

func NewSession added in v1.4.0

func NewSession(ctx context.Context, config config.Config, driver string) (*Session, error)

NewSession creates a new Redis session driver using Goravel's configuration.

func (*Session) Close added in v1.4.0

func (r *Session) Close() error

Close closes the Redis client connection.

func (*Session) Destroy added in v1.4.0

func (r *Session) Destroy(id string) error

Destroy removes a session from Redis.

func (*Session) Gc added in v1.4.0

func (r *Session) Gc(maxLifetime int) error

Gc performs garbage collection. (No-op for Redis TTL-based expiration)

func (*Session) Open added in v1.4.0

func (r *Session) Open(path string, name string) error

func (*Session) Read added in v1.4.0

func (r *Session) Read(id string) (string, error)

Read retrieves session data from Redis.

func (*Session) Write added in v1.4.0

func (r *Session) Write(id string, data string) error

Write saves session data to Redis with the configured lifetime.

type Task added in v1.4.0

type Task struct {
	Job
	UUID  string `json:"uuid"`
	Chain []Job  `json:"chain"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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