func FindTrack(id string) (Track, error) { redisClient := redis.Get() defer redisClient.Close() values, err := redis.Values(redisClient.Do("HGETALL", "gokuraku:track:"+id)) if err != nil { log.Panicln(err) } track := Track{} err = redis.ScanStruct(values, &track) if err != nil { log.Panicln(err) } return track, nil }
func getRandam() *Track { redisClient := redis.Get() defer redisClient.Close() trackId, _ := redis.String(redisClient.Do("SRANDMEMBER", "gokuraku:track-ids")) values, err := redis.Values(redisClient.Do("HGETALL", "gokuraku:track:"+trackId)) if err != nil { panic(err) } track := Track{} err = redis.ScanStruct(values, &track) if err != nil { panic(err) } return &track }
func GetCurrent() (*CurrentTrack, error) { var err error redisClient := redis.Get() defer redisClient.Close() exists, _ := redis.Bool(redisClient.Do("EXISTS", "gokuraku:current-track")) if exists == false { err := updateCurrent() if err != nil { return nil, err } return GetCurrent() } values, err := redis.Values(redisClient.Do("HGETALL", "gokuraku:current-track")) currentTrack := CurrentTrack{} err = redis.ScanStruct(values, ¤tTrack) if err != nil { log.Panicln(err) } err = currentTrack.Validate() if err != nil { currentTrack.Destroy() return nil, err } track, err := FindTrack(currentTrack.TrackId) if err != nil { log.Panicln(err) } return &CurrentTrack{currentTrack.TrackId, currentTrack.StartedAt, &track}, nil }