summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2015-07-17 14:45:50 -0800
committerCorey Hulen <corey@hulen.com>2015-07-17 14:45:50 -0800
commitd65f199e12b19676bfac5e315ee634a8d3f05b88 (patch)
tree5d32f8193910f4a644e17a2c9d389ea3e01dffc0 /store
parentf1329787357544b1f4ecdf36586b93206d56832e (diff)
parent246d12aaf23fa3a2c23225b33a333effff76253b (diff)
downloadchat-d65f199e12b19676bfac5e315ee634a8d3f05b88.tar.gz
chat-d65f199e12b19676bfac5e315ee634a8d3f05b88.tar.bz2
chat-d65f199e12b19676bfac5e315ee634a8d3f05b88.zip
Merge pull request #185 from mattermost/mm-1348
fixes mm-1348 removing dependency on redis
Diffstat (limited to 'store')
-rw-r--r--store/redis.go75
-rw-r--r--store/redis_test.go59
2 files changed, 0 insertions, 134 deletions
diff --git a/store/redis.go b/store/redis.go
deleted file mode 100644
index 262040d43..000000000
--- a/store/redis.go
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-package store
-
-import (
- l4g "code.google.com/p/log4go"
- "github.com/mattermost/platform/model"
- "github.com/mattermost/platform/utils"
- "gopkg.in/redis.v2"
- "strings"
- "time"
-)
-
-var client *redis.Client
-
-func RedisClient() *redis.Client {
-
- if client == nil {
-
- addr := utils.Cfg.RedisSettings.DataSource
-
- client = redis.NewTCPClient(&redis.Options{
- Addr: addr,
- Password: "",
- DB: 0,
- PoolSize: utils.Cfg.RedisSettings.MaxOpenConns,
- })
-
- l4g.Info("Pinging redis at '%v'", addr)
- pong, err := client.Ping().Result()
-
- if err != nil {
- l4g.Critical("Failed to open redis connection to '%v' err:%v", addr, err)
- time.Sleep(time.Second)
- panic("Failed to open redis connection " + err.Error())
- }
-
- if pong != "PONG" {
- l4g.Critical("Failed to ping redis connection to '%v' err:%v", addr, err)
- time.Sleep(time.Second)
- panic("Failed to open ping connection " + err.Error())
- }
- }
-
- return client
-}
-
-func RedisClose() {
- l4g.Info("Closing redis")
-
- if client != nil {
- client.Close()
- client = nil
- }
-}
-
-func PublishAndForget(message *model.Message) {
-
- go func() {
- c := RedisClient()
- result := c.Publish(message.TeamId, message.ToJson())
- if result.Err() != nil {
- l4g.Error("Failed to publish message err=%v, payload=%v", result.Err(), message.ToJson())
- }
- }()
-}
-
-func GetMessageFromPayload(m interface{}) *model.Message {
- if msg, found := m.(*redis.Message); found {
- return model.MessageFromJson(strings.NewReader(msg.Payload))
- } else {
- return nil
- }
-}
diff --git a/store/redis_test.go b/store/redis_test.go
deleted file mode 100644
index 11bd9ca6a..000000000
--- a/store/redis_test.go
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-package store
-
-import (
- "fmt"
- "github.com/mattermost/platform/model"
- "github.com/mattermost/platform/utils"
- "testing"
-)
-
-func TestRedis(t *testing.T) {
- utils.LoadConfig("config.json")
-
- c := RedisClient()
-
- if c == nil {
- t.Fatal("should have a valid redis connection")
- }
-
- pubsub := c.PubSub()
- defer pubsub.Close()
-
- m := model.NewMessage(model.NewId(), model.NewId(), model.NewId(), model.ACTION_TYPING)
- m.Add("RootId", model.NewId())
-
- err := pubsub.Subscribe(m.TeamId)
- if err != nil {
- t.Fatal(err)
- }
-
- // should be the subscribe success message
- // lets gobble that up
- if _, err := pubsub.Receive(); err != nil {
- t.Fatal(err)
- }
-
- PublishAndForget(m)
-
- fmt.Println("here1")
-
- if msg, err := pubsub.Receive(); err != nil {
- t.Fatal(err)
- } else {
-
- rmsg := GetMessageFromPayload(msg)
-
- if m.TeamId != rmsg.TeamId {
- t.Fatal("Ids do not match")
- }
-
- if m.Props["RootId"] != rmsg.Props["RootId"] {
- t.Fatal("Ids do not match")
- }
- }
-
- RedisClose()
-}