Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download api/pkg/cache/redis_cache.go from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/83a59cae175e3c9a43b6f5d3f8749ca61b6b5072/api/pkg/cache/redis_cache.go
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway@83a59cae175e3c9a43b6f5d3f8749ca61b6b5072/api/pkg/cache/redis_cache.go
-
curl -L -o redis_cache.go https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/83a59cae175e3c9a43b6f5d3f8749ca61b6b5072/api/pkg/cache/redis_cache.go
1.36 kB
| package cache | |
| import ( | |
| "context" | |
| "errors" | |
| "time" | |
| "github.com/NdoleStudio/httpsms/pkg/telemetry" | |
| "github.com/NdoleStudio/stacktrace" | |
| "github.com/redis/go-redis/v9" | |
| ) | |
| // redisCache is the Cache implementation in redis | |
| type redisCache struct { | |
| tracer telemetry.Tracer | |
| client *redis.Client | |
| } | |
| // NewRedisCache creates a new instance of RedisCache | |
| func NewRedisCache(tracer telemetry.Tracer, client *redis.Client) Cache { | |
| return &redisCache{ | |
| tracer: tracer, | |
| client: client, | |
| } | |
| } | |
| // Get an item from the redis cache | |
| func (cache *redisCache) Get(ctx context.Context, key string) (value string, err error) { | |
| ctx, span := cache.tracer.Start(ctx) | |
| defer span.End() | |
| response, err := cache.client.Get(ctx, key).Result() | |
| if errors.Is(err, redis.Nil) { | |
| return "", stacktrace.Propagatef(err, "no item found in redis with key [%s]", key) | |
| } | |
| if err != nil { | |
| return "", stacktrace.Propagatef(err, "cannot get item in redis with key [%s]", key) | |
| } | |
| return response, nil | |
| } | |
| // Set an item in the redis cache | |
| func (cache *redisCache) Set(ctx context.Context, key string, value string, ttl time.Duration) error { | |
| ctx, span := cache.tracer.Start(ctx) | |
| defer span.End() | |
| err := cache.client.Set(ctx, key, value, ttl).Err() | |
| if err != nil { | |
| return cache.tracer.WrapErrorSpan(span, stacktrace.Propagatef(err, "cannot set item in redis")) | |
| } | |
| return nil | |
| } | |