- move Cacher from globals to api
- vendorPromotionID for CreatePromotion - LockPromotionSkus
This commit is contained in:
19
business/jxutils/cache/redis/redis.go
vendored
19
business/jxutils/cache/redis/redis.go
vendored
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user