/* DATABASE */ func GetNextID() int { db := redis.NewRedisClient() id, err := strconv.Atoi(db.Get("id_counter").Val()) if err != nil { id = 0 } id += 1 db.Set("id_counter", strconv.Itoa(id), 0) return id }
// FetchUser tries to fetch an user based on an ID func FetchUser(email string) (*User, error) { db := redis.NewRedisClient() u := User{} err := db.GetStruct(email, &u) return &u, err }
// SaveUser stores user in database func (u *User) SaveUser() error { db := redis.NewRedisClient() u.ID = GetNextID() return db.StoreStruct(u.Email, u) }