Sobes.tech
Senior

A new nomenclature (new product) has appeared — should it appear in Redis?

sobes.tech AI

Answer from AI

If the new nomenclature is a new product that needs to be used quickly and efficiently in the application, and Redis is used as a cache or for quick data access, then yes, the new product should appear in Redis. This is usually done to speed up data reading and reduce load on the main database.

When adding a new product, you need to:

  • Update the main database (e.g., SQL or NoSQL).
  • Add or update the corresponding key in Redis so that the cache reflects the current data.

Example in Go using a Redis client:

import (
    "context"
    "github.com/go-redis/redis/v8"
)

func addNewProduct(ctx context.Context, rdb *redis.Client, productID string, productData string) error {
    // Save to the main database (omitted)

    // Update Redis
    err := rdb.Set(ctx, "product:"+productID, productData, 0).Err()
    if err != nil {
        return err
    }
    return nil
}

Thus, Redis will contain up-to-date information about the new product.