test redis connect

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-04-22 23:39:36 +08:00
parent 23c6fa8f18
commit f6ad753345
2 changed files with 28 additions and 1 deletions

View File

@ -44,18 +44,29 @@ func initApp() {
RushStatus.Android.PushError = 0 RushStatus.Android.PushError = 0
} }
func initRedis() { func initRedis() error {
RedisClient = redis.NewClient(&redis.Options{ RedisClient = redis.NewClient(&redis.Options{
Addr: PushConf.Stat.Redis.Addr, Addr: PushConf.Stat.Redis.Addr,
Password: PushConf.Stat.Redis.Password, Password: PushConf.Stat.Redis.Password,
DB: PushConf.Stat.Redis.DB, DB: PushConf.Stat.Redis.DB,
}) })
_, err := RedisClient.Ping().Result()
if err != nil {
// redis server error
LogError.Error("Can't connect redis server: " + err.Error())
return err
}
RushStatus.TotalCount = getTotalCount() RushStatus.TotalCount = getTotalCount()
RushStatus.Ios.PushSuccess = getIosSuccess() RushStatus.Ios.PushSuccess = getIosSuccess()
RushStatus.Ios.PushError = getIosError() RushStatus.Ios.PushError = getIosError()
RushStatus.Android.PushSuccess = getAndroidSuccess() RushStatus.Android.PushSuccess = getAndroidSuccess()
RushStatus.Android.PushError = getAndroidError() RushStatus.Android.PushError = getAndroidError()
return nil
} }
// InitAppStatus for initialize app status // InitAppStatus for initialize app status

View File

@ -51,6 +51,22 @@ func TestAddAndroidError(t *testing.T) {
assert.Equal(t, int64(1000), val) assert.Equal(t, int64(1000), val)
} }
func TestRedisServerSuccess(t *testing.T) {
PushConf.Stat.Redis.Addr = "localhost:6379"
err := initRedis()
assert.NoError(t, err)
}
func TestRedisServerError(t *testing.T) {
PushConf.Stat.Redis.Addr = "localhost:6370"
err := initRedis()
assert.Error(t, err)
}
func TestStatForRedisEngine(t *testing.T) { func TestStatForRedisEngine(t *testing.T) {
var val int64 var val int64
PushConf.Stat.Engine = "redis" PushConf.Stat.Engine = "redis"