- move Cacher from globals to api

- vendorPromotionID for CreatePromotion
- LockPromotionSkus
This commit is contained in:
gazebo
2018-11-07 13:17:25 +08:00
parent ee9b84bd80
commit 9bb30affc4
12 changed files with 291 additions and 163 deletions

View File

@@ -25,8 +25,19 @@ func New(host string, port int, password string) *Cacher {
}
}
func (c *Cacher) FlushAll() error {
return c.client.FlushAll().Err()
func (c *Cacher) FlushKeys(prefix string) (err error) {
if prefix == "" {
return c.client.FlushAll().Err()
}
keys, err := c.Keys(prefix)
if err == nil {
for _, key := range keys {
if err = c.Del(key); err != nil {
break
}
}
}
return err
}
func (c *Cacher) Set(key string, value interface{}, expiration time.Duration) error {
@@ -58,3 +69,7 @@ func (c *Cacher) GetAs(key string, ptr interface{}) error {
}
return err
}
func (c *Cacher) Keys(prefix string) ([]string, error) {
return c.client.Keys(prefix + "*").Result()
}