Add redis

This commit is contained in:
Bel LaPointe
2019-06-19 12:02:07 -06:00
parent 18096443d7
commit 6ac77d247e
5 changed files with 93 additions and 11 deletions

View File

@@ -5,12 +5,12 @@ import (
"strings"
"time"
"github.com/mongodb/mongo-go-driver/mongo"
"github.com/mongodb/mongo-go-driver/mongo/options"
"github.com/mongodb/mongo-go-driver/mongo/readconcern"
"github.com/mongodb/mongo-go-driver/mongo/readpref"
"github.com/mongodb/mongo-go-driver/mongo/writeconcern"
"gopkg.in/mgo.v2/bson"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readconcern"
"go.mongodb.org/mongo-driver/mongo/readpref"
"go.mongodb.org/mongo-driver/mongo/writeconcern"
)
type Mongo struct {
@@ -26,8 +26,8 @@ func NewMongo(addr string, auth ...string) (*Mongo, error) {
Password: auth[1],
})
}
db, err := mongo.NewClientWithOptions(
"mongodb://"+addr,
db, err := mongo.NewClient(
options.Client().ApplyURI("mongodb://"+addr),
options.Client().SetReadConcern(readconcern.Local()),
options.Client().SetReadPreference(readpref.PrimaryPreferred()),
options.Client().SetWriteConcern(writeconcern.New(
@@ -68,8 +68,8 @@ func (mg *Mongo) Get(key string, ns ...string) ([]byte, error) {
return nil, ErrNotFound
}
elem, err := cursor.DecodeBytes()
if err != nil {
var elem bson.Raw
if err := cursor.Decode(&elem); err != nil {
return nil, err
}
raw, err := elem.LookupErr("value")