mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-01 13:48:56 +08:00

* things, twins, and logger lint fixed Signed-off-by: aryan <aryangodara03@gmail.com> * all services updated, auth jwt not working, ineffectual assignment issue Signed-off-by: aryan <aryangodara03@gmail.com> * handle error from grpc server in endpointtest Signed-off-by: aryan <aryangodara03@gmail.com> * temp commit, auth/jwt needs to be resolved Signed-off-by: aryan <aryangodara03@gmail.com> * revert back to jwt v4 temporarily Signed-off-by: aryan <aryangodara03@gmail.com> * updated jwt tokenizer Signed-off-by: aryan <aryangodara03@gmail.com> * resolve EOF error for httptest requests Signed-off-by: aryan <aryangodara03@gmail.com> * fix auth jwt, update to registeredclaims Signed-off-by: aryan <aryangodara03@gmail.com> * fix ineffective assignment, auth/api/grpc endpoint failing Signed-off-by: aryan <aryangodara03@gmail.com> * temp commit, remove later Signed-off-by: aryan <aryangodara03@gmail.com> * fix grpc server setup Signed-off-by: aryan <aryangodara03@gmail.com> * resolve golangci tests, remove debug statements Signed-off-by: aryan <aryangodara03@gmail.com> * update golangci version and modify linters used Signed-off-by: aryan <aryangodara03@gmail.com> * fix failing tests Signed-off-by: aryan <aryangodara03@gmail.com> * fix grpc server for setup tests Signed-off-by: aryan <aryangodara03@gmail.com> * fix logging and errors inlined Signed-off-by: aryan <aryangodara03@gmail.com> * fix remarks, update grpc setup_test Signed-off-by: aryan <aryangodara03@gmail.com> * fix setup_test Signed-off-by: aryan <aryangodara03@gmail.com> * update setup_test grpc Signed-off-by: aryan <aryangodara03@gmail.com> * fix data race Signed-off-by: aryan <aryangodara03@gmail.com> * update setup_test grpc Signed-off-by: aryan <aryangodara03@gmail.com> * fix grpc setup down to single simple function Signed-off-by: aryan <aryangodara03@gmail.com> * fix linting issues Signed-off-by: aryan <aryangodara03@gmail.com> * resolve pr comments Signed-off-by: aryan <aryangodara03@gmail.com> * fix tests, handle returned errors, go mod tidy vendor Signed-off-by: aryan <aryangodara03@gmail.com> * fix errors from new linters Signed-off-by: aryan <aryangodara03@gmail.com> --------- Signed-off-by: aryan <aryangodara03@gmail.com>
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package redis
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
"github.com/mainflux/mainflux/lora"
|
|
)
|
|
|
|
var _ lora.RouteMapRepository = (*routerMap)(nil)
|
|
|
|
type routerMap struct {
|
|
client *redis.Client
|
|
prefix string
|
|
}
|
|
|
|
// NewRouteMapRepository returns redis thing cache implementation.
|
|
func NewRouteMapRepository(client *redis.Client, prefix string) lora.RouteMapRepository {
|
|
return &routerMap{
|
|
client: client,
|
|
prefix: prefix,
|
|
}
|
|
}
|
|
|
|
func (mr *routerMap) Save(ctx context.Context, mfxID, loraID string) error {
|
|
tkey := fmt.Sprintf("%s:%s", mr.prefix, mfxID)
|
|
if err := mr.client.Set(ctx, tkey, loraID, 0).Err(); err != nil {
|
|
return err
|
|
}
|
|
|
|
lkey := fmt.Sprintf("%s:%s", mr.prefix, loraID)
|
|
return mr.client.Set(ctx, lkey, mfxID, 0).Err()
|
|
}
|
|
|
|
func (mr *routerMap) Get(ctx context.Context, id string) (string, error) {
|
|
lKey := fmt.Sprintf("%s:%s", mr.prefix, id)
|
|
mval, err := mr.client.Get(ctx, lKey).Result()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return mval, nil
|
|
}
|
|
|
|
func (mr *routerMap) Remove(ctx context.Context, mfxID string) error {
|
|
mkey := fmt.Sprintf("%s:%s", mr.prefix, mfxID)
|
|
lval, err := mr.client.Get(ctx, mkey).Result()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
lkey := fmt.Sprintf("%s:%s", mr.prefix, lval)
|
|
return mr.client.Del(ctx, mkey, lkey).Err()
|
|
}
|