K
K
Kagtaviy2016-05-21 12:53:19
go
Kagtaviy, 2016-05-21 12:53:19

How to display data?

Hello, I can not figure out how to display data from redis.
I have a form:
a0f476a7425b47b984d44414b46899e5.png
after I filled in the fields, the form is sent, it processes and passes the data to the radish, this is the output:
8dd8c0058e1f4e6d90dc4d55e74f9340.png86cb4d7dc64141d28831829d8346fcaf.png
This is how I generate the id:
f83ccfcfc31f466885ec8f99d5f7c0f0.png

func setNews(title, url, desc, t string) {
  id, err := client.Get("news:id").Result()
  if err != nil {                       
    client.Set("news:id", "0", 0)
  }
  client.Incr("news:id")                                                                  
  client.HMSet("news:"+id, "id", id, "title", title, "url", url, "desc", desc, "time", t) 
  client.Close()                                                                          
}

Now I need to request all the news from the radish and display it in a template.
I can output data to a template, but I can’t figure out how to correctly request them from a radish.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Grabko, 2016-05-21
@VGrabko

You need to make another news index in which to store all the keys to select from the radish (slice []string).
Also, every n minutes, clone this slice into a radish, and then, when restarting, read it from there

Анатолий, 2016-05-29
@taliban

У меня встречный вопрос, зачем пытаться использовать редис как реляционную бд?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question