I am trying to Set Data to Redis at (6 am, 12 pm, 6 pm and 12 am). But all I can do is setting an expiration time for data caching in redis. Is there any way in Golang to do this?
Code:
err := client.Set(key, data[]byte, 6 * time.Hour).Err()
I am trying to Set Data to Redis at (6 am, 12 pm, 6 pm and 12 am). But all I can do is setting an expiration time for data caching in redis. Is there any way in Golang to do this?
Code:
err := client.Set(key, data[]byte, 6 * time.Hour).Err()
Since you want to add data in redis at evry 6 hours. You should use cronjob for this.
I have created a sample scenario which might help you as follows:
For better understanding you can refer gocron package.
s := gocron.NewScheduler(time.UTC)
s.Every(6).Hours().Do(func(){ //you can change it
err := client.Set(ctx, "key", "value", 0).Err() //your logic
if err != nil {
panic(err)
}
})