Created
March 8, 2018 16:02
-
-
Save dimiro1/52a348d1f20535f6df4c55ace1c4b66b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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