Skip to content

Commit

Permalink
add redis backend
Browse files Browse the repository at this point in the history
  • Loading branch information
pyama86 committed Mar 31, 2019
1 parent 09e229f commit ef3370f
Show file tree
Hide file tree
Showing 8 changed files with 408 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ repo/*
etcd*
default.etcd
.vagrant
redis*
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ before_install:
script:
- make etcd
- while ! nc -w 1 127.0.0.1 2379 > /dev/null 2>&1; do sleep 1; echo 'sleeping'; done;
- make redis
- while ! nc -w 1 127.0.0.1 6379 > /dev/null 2>&1; do sleep 1; echo 'sleeping'; done;
- sudo PATH=$PATH GOPATH=$GOPATH GO="GO111MODULE=on go" make ci
go:
- 1.12
Expand Down
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ MODDIR ?= $(PREFIX)/local/stns/modules.d
SOURCES=Makefile go.mod go.sum version model api middleware modules stns stns.go package/
DISTS=centos7 centos6 ubuntu16
ETCD_VER=3.3.10
REDIS_VER=5.0.4
BUILD=tmp/bin
UNAME_S := $(shell uname -s)

Expand All @@ -42,6 +43,18 @@ ifeq ($(UNAME_S),Darwin)
brew services start etcd
endif

redis:
echo $(UNAME_S)
ifeq ($(UNAME_S),Linux)
test -e ./redis-$(REDIS_VER).tar.gz || curl -L http://download.redis.io/releases/redis-$(REDIS_VER).tar.gz -o redis-$(REDIS_VER).tar.gz
test -d ./redis-$(REDIS_VER) || tar xzf redis-$(REDIS_VER).tar.gz
test -e ./redis-$(REDIS_VER)/src/redis-server || (cd ./redis-$(REDIS_VER) && make)
ps -aux |grep redis |grep -q -v grep || ./redis-$(REDIS_VER)/src/redis-server &
endif
ifeq ($(UNAME_S),Darwin)
brew services start redis
endif

depsdev: ## Installing dependencies for development
$(GO) get -u golang.org/x/lint/golint
$(GO) get -u github.com/tcnksm/ghr
Expand All @@ -53,7 +66,7 @@ changelog:
git-chglog -o CHANGELOG.md

test: ## Run test
@echo "$(INFO_COLOR)==> $(RESET)$(BOLD)Testing$(RESET)"
@echo "$(INFO_COLOR)==> $(RESET)$(BOLD)Testing$(RESET) (require: etcd,redis)"
$(GO) test -v $(TEST) -timeout=30s -parallel=4
$(GO) test -race $(TEST)

Expand Down
9 changes: 9 additions & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ func LaunchServer(c *cli.Context) error {
if b != nil {
backend = b
}

if conf.Redis.Host != "" {
r, err := model.NewBackendRedis(backend, logger, conf.Redis.Host, conf.Redis.Port, conf.Redis.Password, conf.Redis.TTL, conf.Redis.DB)
if err != nil {
return err
}
backend = r
}

// set log output
if os.Getenv("STNS_LOG") != "" {
f, err := os.OpenFile(os.Getenv("STNS_LOG"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/go-playground/locales v0.12.1 // indirect
github.com/go-playground/universal-translator v0.16.0 // indirect
github.com/go-redis/redis v6.15.2+incompatible
github.com/go-toolsmith/astcast v1.0.0 // indirect
github.com/go-toolsmith/astcopy v1.0.0 // indirect
github.com/go-toolsmith/astfmt v1.0.0 // indirect
Expand Down Expand Up @@ -95,6 +96,7 @@ require (
gopkg.in/AlecAivazis/survey.v1 v1.8.2 // indirect
gopkg.in/go-playground/validator.v9 v9.27.0
gopkg.in/kyokomi/emoji.v1 v1.5.1 // indirect
gopkg.in/redis.v5 v5.2.9
gopkg.in/yaml.v2 v2.2.2 // indirect
mvdan.cc/unparam v0.0.0-20190310220240-1b9ccfa71afe // indirect
sourcegraph.com/sqs/pbtypes v1.0.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ github.com/go-playground/locales v0.12.1 h1:2FITxuFt/xuCNP1Acdhv62OzaCiviiE4kotf
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM=
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDAhzyXg+Bs+0Sb4=
github.com/go-redis/redis v6.15.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-toolsmith/astcast v0.0.0-20181028201508-b7a89ed70af1/go.mod h1:TEo3Ghaj7PsZawQHxT/oBvo4HK/sl1RcuUHDKTTju+o=
github.com/go-toolsmith/astcast v1.0.0 h1:JojxlmI6STnFVG9yOImLeGREv8W2ocNUM+iOhR6jE7g=
github.com/go-toolsmith/astcast v1.0.0/go.mod h1:mt2OdQTeAQcY4DQgPSArJjHCcOwlX+Wl/kwN+LbLGQ4=
Expand Down Expand Up @@ -325,6 +327,7 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpbl
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc h1:4gbWbmmPFp4ySWICouJl6emP0MyS31yy9SrTlAGFT+g=
golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65 h1:hOY+O8MxdkPV10pNf7/XEHaySCiPKxixMKUshfHsGn0=
golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20170915090833-1cbadb444a80/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
Expand Down Expand Up @@ -360,6 +363,8 @@ gopkg.in/go-playground/validator.v9 v9.27.0 h1:wCg/0hk9RzcB0CYw8pYV6FiBYug1on0cp
gopkg.in/go-playground/validator.v9 v9.27.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
gopkg.in/kyokomi/emoji.v1 v1.5.1 h1:beetH5mWDMzFznJ+Qzd5KVHp79YKhVUMcdO8LpRLeGw=
gopkg.in/kyokomi/emoji.v1 v1.5.1/go.mod h1:N9AZ6hi1jHOPn34PsbpufQZUcKftSD7WgS2pgpmH4Lg=
gopkg.in/redis.v5 v5.2.9 h1:MNZYOLPomQzZMfpN3ZtD1uyJ2IDonTTlxYiV/pEApiw=
gopkg.in/redis.v5 v5.2.9/go.mod h1:6gtv0/+A4iM08kdRfocWYB3bLX2tebpNtfKlFT6H4mY=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
Loading

0 comments on commit ef3370f

Please sign in to comment.