func (r *RedisLeaderboard) AddMember(member string, score float64) {
	if r.redis_connection != nil {
		_, err := r.redis_connection.Do("ZADD", r.leaderboard_name, score, member)
		if err != nil {
			logger.Get().Debug("Error is : " + err.Error())
		}
	}
}
func (r *RedisLeaderboard) RemoveMember(member string) {
	if r.redis_connection != nil {
		_, err := r.redis_connection.Do("ZREM", r.leaderboard_name, member)
		if err != nil {
			logger.Get().Debug("Error is : " + err.Error())
		}
	}
}
func (r *RedisHash) AddHashValue(key string, value string) {
	if r.redis_connection != nil {
		_, err := r.redis_connection.Do("HSET", r.hash_name, key, value)
		if err != nil {
			logger.Get().Debug("Error is : " + err.Error())
		}
	}
}
func (r *RedisHash) RemoveHashValue(key string) {
	if r.redis_connection != nil {
		_, err := r.redis_connection.Do("HDEL", r.hash_name, key)
		if err != nil {
			logger.Get().Debug("Error is : " + err.Error())
		}
	}
}
Exemple #5
0
func main() {

	initModules()

	defer model.Db.Close()

	r := router.RouteHandler()

	port := config.Port
	logger.Get().SetLogLevel(3)
	logger.Get().Debug("Port is : " + port)
	n := negroni.Classic()
	n.Use(middleware.NewResponse())
	n.Use(middleware.NewUserAuth())
	n.UseHandler(r)
	n.Run(port)
}
func PostMessageOnQueue(queue_name, message string) {
	redisMessageQueue := GetRedisMessageQueueInstance()
	_, err := redisMessageQueue.GetRedisConnection().Do("RPUSH", queue_name, message)
	if err != nil {
		logger.Get().Debug("Error is : " + err.Error())
	}
	redisMessageQueue.CloseConn()
}
func (r *RedisMessageQueue) PostMessage(list, message string) {
	if r.redis_connection != nil {
		_, err := redis.String(r.redis_connection.Do("RPUSH", list, message))
		if err != nil {
			logger.Get().Debug("Error is : " + err.Error())
		}
	}
}
func (r *RedisPublisher) PublishMessage(message string) {
	if r.redis_connection != nil {
		_, err := r.redis_connection.Do("PUBLISH", r.channel, message)
		if err != nil {
			logger.Get().Debug("Error is : " + err.Error())
		}
	}
}
func (r *RedisLeaderboard) MemberRank(member string) int {
	if r.redis_connection != nil {
		count, err := redis.Int(r.redis_connection.Do("ZREVRANK", r.leaderboard_name, member))
		if err != nil {
			logger.Get().Debug("Error is : " + err.Error())
		}
		return count
	}
	return -1
}
func (r *RedisLeaderboard) TotalMembers() int {
	if r.redis_connection != nil {
		count, err := redis.Int(r.redis_connection.Do("ZCARD", r.leaderboard_name))
		if err != nil {
			logger.Get().Debug("Error is : " + err.Error())
		}
		return count
	}
	return 0
}
func (r *RedisHash) GetHashValue(key string) string {
	if r.redis_connection != nil {
		value, err := redis.String(r.redis_connection.Do("HGET", r.hash_name, key))
		if err != nil {
			logger.Get().Debug("Error is : " + err.Error())
		}
		return value
	}
	return ""
}
func (r *RedisHash) TotalValue() int {
	if r.redis_connection != nil {
		count, err := redis.Int(r.redis_connection.Do("HGETALL", r.hash_name))
		if err != nil {
			logger.Get().Debug("Error is : " + err.Error())
		}
		return count
	}
	return 0
}
func (r *RedisHash) SetHashFromMap(mapValues map[string]string) {
	if r.redis_connection != nil {
		r.redis_connection.Send("MULTI")
		for key := range mapValues {
			r.redis_connection.Send("HSET", r.hash_name, key, mapValues[key])
		}
		_, err := r.redis_connection.Do("EXEC")
		if err != nil {
			logger.Get().Debug("Error is : " + err.Error())
		}
	}
}
func (r *RedisConnectionPool) newPool() *redis.Pool {
	return &redis.Pool{
		MaxIdle:   80,
		MaxActive: 12000, // max number of connections
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("tcp", config.Redis_Address)
			if err != nil {
				logger.Get().Debug("Error while connecting : " + err.Error())
			}
			return c, err
		},
	}

}
func (r *RedisLeaderboard) GetLeaders(currentPage int) []string {
	if r.redis_connection != nil {
		if currentPage < 1 {
			currentPage = 1
		}
		startOffset := (currentPage - 1) * r.page_size
		if startOffset < 0 {
			startOffset = 0
		}
		endOffset := startOffset + r.page_size - 1
		leaderData, err := redis.Strings(r.redis_connection.Do("ZREVRANGE", r.leaderboard_name, startOffset, endOffset))
		if err != nil {
			logger.Get().Debug("Error is : " + err.Error())
		}
		return leaderData
	}
	return nil
}