init project
This commit is contained in:
1 parent
d63cc8d9f5
commit
ee07869839
39 files changed
+1560
-622
No files matched your search
Vendored
+10
-10
@@ -5,8 +5,8 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.xiaotuo.co/micro/skeleton/internal/logger"
|
||||
"github.com/go-redis/redis"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"micro_layout/internal/logger"
|
||||
)
|
||||
|
||||
type BaseCache struct {
|
||||
@@ -15,7 +15,7 @@ type BaseCache struct {
|
||||
}
|
||||
|
||||
func (c *BaseCache) exists(ctx context.Context, key string) (bool, error) {
|
||||
value, err := c.rs.Exists(key).Result()
|
||||
value, err := c.rs.Exists(ctx, key).Result()
|
||||
if errors.Is(err, redis.Nil) {
|
||||
if c.isLog {
|
||||
logger.Debugf(ctx, "redis_exists", "key: %s, not_found", key)
|
||||
@@ -36,7 +36,7 @@ func (c *BaseCache) exists(ctx context.Context, key string) (bool, error) {
|
||||
}
|
||||
|
||||
func (c *BaseCache) get(ctx context.Context, key string) (string, error) {
|
||||
value, err := c.rs.Get(key).Result()
|
||||
value, err := c.rs.Get(ctx, key).Result()
|
||||
if err != nil {
|
||||
if c.isLog {
|
||||
logger.Errorf(ctx, "redis_get", "key: %s, err: %v", key, err)
|
||||
@@ -50,7 +50,7 @@ func (c *BaseCache) get(ctx context.Context, key string) (string, error) {
|
||||
}
|
||||
|
||||
func (c *BaseCache) set(ctx context.Context, key string, value interface{}, expire time.Duration) (string, error) {
|
||||
result, err := c.rs.Set(key, value, expire).Result()
|
||||
result, err := c.rs.Set(ctx, key, value, expire).Result()
|
||||
if err != nil {
|
||||
if c.isLog {
|
||||
logger.Errorf(ctx, "redis_set", "key: %s, value: %v, err: %v", key, value, err)
|
||||
@@ -64,7 +64,7 @@ func (c *BaseCache) set(ctx context.Context, key string, value interface{}, expi
|
||||
}
|
||||
|
||||
func (c *BaseCache) del(ctx context.Context, key string) (int64, error) {
|
||||
affect, err := c.rs.Del(key).Result()
|
||||
affect, err := c.rs.Del(ctx, key).Result()
|
||||
if err != nil {
|
||||
if c.isLog {
|
||||
logger.Errorf(ctx, "redis_del", "key: %s, err: %v", key, err)
|
||||
@@ -78,7 +78,7 @@ func (c *BaseCache) del(ctx context.Context, key string) (int64, error) {
|
||||
}
|
||||
|
||||
func (c *BaseCache) push(ctx context.Context, key string, values ...interface{}) (int64, error) {
|
||||
affect, err := c.rs.LPush(key, values...).Result()
|
||||
affect, err := c.rs.LPush(ctx, key, values...).Result()
|
||||
if err != nil {
|
||||
if c.isLog {
|
||||
logger.Errorf(ctx, "redis_lpush", "key: %s, err: %v", key, err)
|
||||
@@ -92,7 +92,7 @@ func (c *BaseCache) push(ctx context.Context, key string, values ...interface{})
|
||||
}
|
||||
|
||||
func (c *BaseCache) pop(ctx context.Context, key string) (string, error) {
|
||||
value, err := c.rs.RPop(key).Result()
|
||||
value, err := c.rs.RPop(ctx, key).Result()
|
||||
if errors.Is(err, redis.Nil) {
|
||||
if c.isLog {
|
||||
logger.Tracef(ctx, "redis_rpop", "key: %s null", key)
|
||||
@@ -112,7 +112,7 @@ func (c *BaseCache) pop(ctx context.Context, key string) (string, error) {
|
||||
}
|
||||
|
||||
func (c *BaseCache) length(ctx context.Context, key string) (int64, error) {
|
||||
l, err := c.rs.LLen(key).Result()
|
||||
l, err := c.rs.LLen(ctx, key).Result()
|
||||
if errors.Is(err, redis.Nil) {
|
||||
if c.isLog {
|
||||
logger.Debugf(ctx, "redis_llen", "key: %s null", key)
|
||||
@@ -132,7 +132,7 @@ func (c *BaseCache) length(ctx context.Context, key string) (int64, error) {
|
||||
}
|
||||
|
||||
func (c *BaseCache) lock(ctx context.Context, key, value string, expire time.Duration) (bool, error) {
|
||||
result, err := c.rs.SetNX(key, value, expire).Result()
|
||||
result, err := c.rs.SetNX(ctx, key, value, expire).Result()
|
||||
if err != nil {
|
||||
if c.isLog {
|
||||
logger.Errorf(ctx, "redis_setnx", "key: %s, err: %v", key, err)
|
||||
|
||||
Reference in new issue
Block a user