# README

Redis Client

This is a Redis client wrapper for Golang that provides a simplified interface to interact with Redis.

Installation

To use this library install using the go get commant

go get -u github.com/SimifiniiCTO/backend-core-lib/database/redis

Usage

To use this library first import

import github.com/SimifiniiCTO/backend-core-lib/database/redis
import github.com/SimifiniiCTO/backend-core-lib/signals

Create The Client

To create a new Redis client, use the New function:

    stopCh := signals.SetupSignalHandler()
    opts := []redis.Options{
        redis.WithLogger(zap.L()),
        redis.WithTelemetrySdk(&instrumentation.Client{}),
        redis.WithURI(host),
        redis.WithServiceName(serviceName), 
        redis.WithCacheTTLInSeconds(cacheTTLInSeconds),
    }

    c, err := redis.New(stopCh, opts...)
    if err != nil {
        ...
    }

Where:

  • host: the Redis server host (string).
  • serviceName: the service initialization the redis connection
  • logger: zap logger instance
  • cacheTTLInSeconds: the TTL (in seconds) for cache entries (int).
  • telemetrySdk: the telemetry SDK to use (an object implementing the ITelemetrySdk interface).

Reading data from Redis

To read data from Redis, use the Read function:

value, err := client.Read(ctx, key)
if err != nil {
    // handle error
}

Where:

  • ctx: the context (context.Context) for the Redis read operation.
  • key: the key (string) for the data to read.

Deleting data from Redis

To delete data from Redis, use the Delete function:

err := client.Delete(ctx, key)
if err != nil {
    // handle error
}

Where:

  • ctx: the context (context.Context) for the Redis delete operation.
  • key: the key (string) for the data to read.

Testing

To run the unit tests, use the go test command:

go test -v

Contributing

Contributions to this Redis client are welcome. To contribute, follow these steps:

  • Fork this repository.
  • Create a new branch: git checkout -b my-new-feature.
  • Make changes and add tests for the new feature.
  • Run tests and ensure they pass: go test -v.
  • Commit your changes: git commit -am 'Add some feature'.
  • Push to the branch: git push origin my-new-feature.
  • Create a new Pull Request.

License

This Redis client is released under the MIT License. See LICENSE for more information.

# Functions

New creates a new client with optional configurations and a stop channel.
WithCacheTTLInSeconds sets the cache TTL in seconds for the Redis client.
WithLogger sets the logger for the Redis client.
WithServiceName sets the service name for the Redis client.
WithTelemetrySdk sets the telemetry SDK for the Redis client.
No description provided by the author
WithURI sets the URI for the Redis client.

# Constants

Defining a constant named `RedisDeleteFromCacheTxn` of type `DatastoreTxName` and assigning it the value `"txn.redis.delete-from-cache"`.
`RedisReadFromCacheTxn` of type `DatastoreTxName` and assigning it the value `"txn.redis.read-from-cache"`.
Defining a constant named `RedisReadManyFromCacheTxn` of type `DatastoreTxName` and assigning it the value `"txn.redis.read-many-from-cache"`.
Defining a constant named `RedisWriteToCacheTxn` of type `DatastoreTxName` and assigning it the value `"txn.redis.write-to-cache"`.
Defining a constant named `RedisWriteToCacheWithTTLTxn` of type `DatastoreTxName` and assigning it the value `"txn.redis.write-to-cache-with-ttl"`.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

The `Client` type contains various fields related to a Redis client in a Go program, including a connection pool, cache TTL, telemetry SDK, URI, and logger.

# Type aliases

No description provided by the author
Option configures the redis client properly.