Skip to content

Instantly share code, notes, and snippets.

@dimiro1
Created March 8, 2018 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimiro1/52a348d1f20535f6df4c55ace1c4b66b to your computer and use it in GitHub Desktop.
Save dimiro1/52a348d1f20535f6df4c55ace1c4b66b to your computer and use it in GitHub Desktop.
package main
import (
"context"
"github.com/garyburd/redigo/redis"
)
//TranslationsPipe interface {
//Pipe(ctx context.Context, source dbTranslations.TranslationSource, dest cacheTranslations.TranslationsManager, ids []uint64, defaultNames map[uint64]string) error
//}
type Cacheable interface{
// To hold metadata information about the specific entry
Metadata() map[string]interface{}
}
type Cacher interface {
Cache(context.Context, []Cacheable) error
}
type CustomNamesCacher struct {
namespace string
connector redis.Conn
}
func (c *CustomNamesCacher) Cache(ctx context.Context, entries []Cacheable) error {
err := c.connector.Send("MULTI")
if err != nil {
return err
}
for _, entry := range entries {
// You can extract metadata from the Metadata function or
// you can cast the entry to the specific type if you want
for language, customNames := range languageCustomNames {
customNamesKey := fmt.Sprintf(customNamesKeyPattern, m.namespace, competitionID, language)
err = conn.Send(ctx, "SADD", redis.Args{customNamesKey}.AddFlat(customNames)...)
if err != nil {
return err
}
}
}
_, err = conn.Do(ctx, "EXEC")
return err
}
func main() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment