# 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.