O'Reilly logo

Isomorphic Go by Kamesh Balasubramanian

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Retrieving products from the datastore

Let's examine the GetProducts method defined in the common/datastore/redis.go source file:

func (r *RedisDatastore) GetProducts() []*models.Product {  registryKey := "product-registry"  exists, err := r.Cmd("EXISTS", registryKey).Int()  if err != nil {    log.Println("Encountered error: ", err)    return nil  } else if exists == 0 {    return nil  }  var productKeys []string  jsonData, err := r.Cmd("GET", registryKey).Str()  if err != nil {    log.Print("Encountered error when attempting to fetch product registry data from Redis instance: ", err)    return nil  }  if err := json.Unmarshal([]byte(jsonData), &productKeys); err != nil { log.Print("Encountered error when attempting to unmarshal JSON product registry data: ", err) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required