feat: CR login, register, subscribe
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package cachingsvc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
cachingdomain "github.com/ardeman/project-legalgo-go/internal/domain/caching"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
type impl struct {
|
||||
redisClient *redis.Client
|
||||
}
|
||||
|
||||
type implIntf interface {
|
||||
Set(context.Context, cachingdomain.CacheSpec) error
|
||||
}
|
||||
|
||||
func New() implIntf {
|
||||
return &impl{}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package cachingsvc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
cachingdomain "github.com/ardeman/project-legalgo-go/internal/domain/caching"
|
||||
"github.com/ardeman/project-legalgo-go/internal/utilities/response"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (i *impl) Set(ctx context.Context, spec cachingdomain.CacheSpec) error {
|
||||
redisClient := i.redisClient
|
||||
|
||||
if redisClient == nil {
|
||||
logrus.WithContext(ctx).Errorf("redis not found")
|
||||
|
||||
return response.ErrRedisConnNotFound
|
||||
}
|
||||
|
||||
dataBytes, err := json.Marshal(spec.Data)
|
||||
if err != nil {
|
||||
return response.ErrMarshal
|
||||
}
|
||||
|
||||
if err := redisClient.Set(ctx, spec.Key, string(dataBytes), spec.TTL); err != nil {
|
||||
return response.ErrRedisSet
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user