1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-29 13:49:28 +08:00
Aleksandar Novaković 61f1c2e379 MF-399 - Add open tracing support (#782)
* Add open tracing dependencies

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Add open tracing to users service

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Add open tracing to the things service

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Add open tracing to the http adapter

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Add open tracing to the ws adapter

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Add open tracing to the CoAP adapter

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Update LoRa adapter in accordance with changes

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Update SDK tests in accordance with changes

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Update bootstrap service in accordance with changes

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Update reader services with accordance with changes

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Update .env and docker-compose file

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Add jaeger and timeout env vars

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Fix broken test for can access by id endpoint

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Update deps with proto empty package

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>
2019-07-18 15:01:09 +02:00

56 lines
1.2 KiB
Go

//
// Copyright (c) 2019
// Mainflux
//
// SPDX-License-Identifier: Apache-2.0
//
package redis
import (
"context"
"fmt"
"github.com/go-redis/redis"
"github.com/mainflux/mainflux/things"
)
const chanPrefix = "channel"
var _ things.ChannelCache = (*channelCache)(nil)
type channelCache struct {
client *redis.Client
}
// NewChannelCache returns redis channel cache implementation.
func NewChannelCache(client *redis.Client) things.ChannelCache {
return channelCache{client: client}
}
func (cc channelCache) Connect(_ context.Context, chanID, thingID string) error {
cid, tid := kv(chanID, thingID)
return cc.client.SAdd(cid, tid).Err()
}
func (cc channelCache) HasThing(_ context.Context, chanID, thingID string) bool {
cid, tid := kv(chanID, thingID)
return cc.client.SIsMember(cid, tid).Val()
}
func (cc channelCache) Disconnect(_ context.Context, chanID, thingID string) error {
cid, tid := kv(chanID, thingID)
return cc.client.SRem(cid, tid).Err()
}
func (cc channelCache) Remove(_ context.Context, chanID string) error {
cid, _ := kv(chanID, "0")
return cc.client.Del(cid).Err()
}
// Generates key-value pair
func kv(chanID, thingID string) (string, string) {
cid := fmt.Sprintf("%s:%s", chanPrefix, chanID)
return cid, thingID
}