modulepackage
1.1.0
Repository: https://github.com/golanguzb70/redis-cache.git
Documentation: pkg.go.dev
# README
Redis Cache Package
The rediscache
package provides a convenient way to implement caching using Redis. It combines Redis and hashing algorithms in one place, making it faster to implement caching in your applications.
Installation
To install the rediscache
package, use the following command:
go get github.com/golanguzb70/redis-cache
Usage
Import the rediscache
package in your Go code:
import "github.com/golanguzb70/redis-cache"
Create a new Redis cache instance by calling the New
function and passing a Config
object:
cfg := &rediscache.Config{
RedisHost: "localhost",
RedisPort: 6379,
RedisUsername: "your-redis-username",
RedisPassword: "your-redis-password",
}
cache, err := rediscache.New(cfg)
if err != nil {
// handle error
}
Cache Operations
Set
Store a key-value pair in the cache:
err := cache.Set(ctx, key, value, expiration)
if err != nil {
// handle error
}
Get
Retrieve a value from the cache using a key:
value, err := cache.Get(ctx, key)
if err != nil {
// handle error
}
Del
Delete a key from the cache:
err := cache.Del(ctx, key)
if err != nil {
// handle error
}
DelWildCard
Delete all keys that match a wildcard pattern:
err := cache.DelWildCard(ctx, wildcard)
if err != nil {
// handle error
}
Ping
Check if the cache is available:
err := cache.Ping(ctx)
if err != nil {
// handle error
}
HashOject
Generate a hash for a given object:
hash := cache.HashOject(obj)
Hash
Generate a hash for a given key:
hash := cache.Hash(key)
For more information, refer to the Redis Go client documentation.
# Functions
No description provided by the author
# Interfaces
No description provided by the author