Skip to content
Snippets Groups Projects
Commit 5f470b0a authored by thijsheijden's avatar thijsheijden
Browse files

Renamed keyvaluedriver to keyvaluestore

parent 8873ba5b
No related branches found
No related tags found
No related merge requests found
......@@ -9,18 +9,18 @@ import (
"github.com/go-redis/redis/v8"
)
// KeyValueDriver models the redis driver
type KeyValueDriver struct {
// KeyValueStore models the redis driver
type KeyValueStore struct {
client *redis.Client
}
// NewRedisDriver creates and returns a redis driver
func NewRedisDriver() *KeyValueDriver {
return &KeyValueDriver{}
func NewRedisDriver() *KeyValueStore {
return &KeyValueStore{}
}
// Start starts the redis driver
func (d *KeyValueDriver) Start() {
func (d *KeyValueStore) Start() {
// Grab the redis host and port from environment vars
redisAddress := os.Getenv("REDIS_ADDRESS")
// redisPassword := os.Getenv("REDIS_PASSWORD")
......@@ -35,12 +35,12 @@ func (d *KeyValueDriver) Start() {
}
// Get retrieves the value from the redis store that belongs to the given key
func (d *KeyValueDriver) Get(key *string) string {
func (d *KeyValueStore) Get(key *string) string {
return d.client.Get(context.Background(), *key).Val()
}
// Set sets the key value pair in the redis store
func (d *KeyValueDriver) Set(key *string, value *string) error {
func (d *KeyValueStore) Set(key *string, value *string) error {
status := d.client.Set(context.Background(), *key, *value, 0)
return status.Err()
}
package produce
import (
"fmt"
"query-service/pkg/logger"
"github.com/streadway/amqp"
)
......@@ -9,9 +12,12 @@ func (s *Service) PublishMessage(data *[]byte, sessionID *string) {
// Use the sessionID to query the key value store to get the queue we need to send this message to
clientQueueID := s.keyValueStore.Get(sessionID)
logger.Log(fmt.Sprintf("Found client queue %s for session %s", clientQueueID, *sessionID))
// If this client has now disconnected
if clientQueueID == "" {
// TODO: Decide whether to throw away the message or perhaps cache it, for now throw it away
logger.Log("No client updater queue ID")
return
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment