This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.0" | |
services: | |
redis: | |
image: "redis:alpine" | |
# The Command will make redis-server run with our custom Configuration | |
command: redis-server /usr/local/etc/redis/redis.conf | |
volumes: | |
- ./redis/data:/data #Used for persisting data | |
- ./redis/conf:/usr/local/etc/redis #Used for configuring redis | |
networks: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"encoding/json" | |
"math/rand" | |
"time" | |
"github.com/go-redis/redis/v8" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"time" | |
"github.com/go-redis/redis/v8" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Engine is a interface that declares what methods a pub/sub engine needs in Go4Data | |
type Engine interface { | |
Publish(key string, payloads ...payload.Payload) []PublishingError | |
PublishTopics(topics []string, payloads ...payload.Payload) []PublishingError | |
Subscribe(key string, pid uint, queueSize int) (*Pipe, error) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pubsub | |
import "github.com/percybolmer/go4data/payload" | |
// Engine is a interface that declares what methods a pub/sub engine needs in Go4Data | |
type Engine interface { | |
Publish(key string, payloads ...payload.Payload) []PublishingError | |
PublishTopics(topics []string, payloads ...payload.Payload) []PublishingError | |
Subscribe(key string, pid uint, queueSize int) (*Pipe, error) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pubsub | |
import ( | |
"errors" | |
"sync" | |
"time" | |
"github.com/percybolmer/go4data/payload" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Package pubsub contains defaultEngine is the default built-in Channel based engine | |
// used to pubsub | |
package pubsub | |
import ( | |
"errors" | |
"sync" | |
"time" | |
"github.com/percybolmer/go4data/payload" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pubsub | |
import ( | |
"context" | |
"errors" | |
"github.com/go-redis/redis/v8" | |
"github.com/percybolmer/go4data/payload" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This shows how to change the whole Go4Data to use Redis instead | |
_, err := pubsub.NewEngine(WithRedisEngine(&redis.Options{ | |
Addr: "localhost:6379", | |
Password: "", | |
DB: 0, | |
}) | |
// This is how we would change back to DefaultEngine | |
_, err := pubsub.NewEngine(WithDefaultEngine(2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pubsub | |
import ( | |
"testing" | |
"github.com/go-redis/redis/v8" | |
"github.com/percybolmer/go4data/payload" | |
) | |
// We create the redisEngine to avoid including connection time during the tests |