1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-27 13:48:49 +08:00
Dušan Borovčanin 516c02bebe
MF-1378 - Update dependencies (#1379)
* Update dependencies

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Fix compose files and configs

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Upgrade image versions

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Update Postgres version

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Update test dependencies

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Fix fkey error handling

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
2021-05-20 20:53:56 +02:00

63 lines
1.4 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/opcua"
)
var _ opcua.RouteMapRepository = (*routerMap)(nil)
type routerMap struct {
client *redis.Client
prefix string
}
// NewRouteMapRepository returns redis thing cache implementation.
func NewRouteMapRepository(client *redis.Client, prefix string) opcua.RouteMapRepository {
return &routerMap{
client: client,
prefix: prefix,
}
}
func (mr *routerMap) Save(ctx context.Context, mfxID, opcuaID string) error {
tkey := fmt.Sprintf("%s:%s", mr.prefix, mfxID)
if err := mr.client.Set(ctx, tkey, opcuaID, 0).Err(); err != nil {
return err
}
lkey := fmt.Sprintf("%s:%s", mr.prefix, opcuaID)
if err := mr.client.Set(ctx, lkey, mfxID, 0).Err(); err != nil {
return err
}
return nil
}
func (mr *routerMap) Get(ctx context.Context, opcuaID string) (string, error) {
lKey := fmt.Sprintf("%s:%s", mr.prefix, opcuaID)
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()
}