Skip to content

Commit

Permalink
Merge pull request #138 from lhui1991/master
Browse files Browse the repository at this point in the history
add redis mget/mset
  • Loading branch information
niubell authored Jan 16, 2020
2 parents d336c09 + ad3588b commit 0d83bbb
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cache/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,38 @@ func (m *Client) Get(ctx context.Context, key string) *redis.StringCmd {
return m.client.Get(k)
}

func (m *Client) MGet(ctx context.Context, keys ...string) *redis.SliceCmd {
var fixKeys = make([]string, len(keys))
for k,v := range keys {
key := m.fixKey(v)
fixKeys[k] = key
}
m.logSpan(ctx, "MGet", strings.Join(fixKeys, "||"))
return m.client.MGet(fixKeys...)
}

func (m *Client) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd {
k := m.fixKey(key)
m.logSpan(ctx, "Set", k)
return m.client.Set(k, value, expiration)
}

func (m *Client) MSet(ctx context.Context, pairs ...interface{}) *redis.StatusCmd {
var fixPairs = make([]interface{}, len(pairs))
var keys []string
for k,v := range pairs {
if (k & 1) == 0 {
key := m.fixKey(v.(string))
keys = append(keys, key)
fixPairs[k] = key
} else {
fixPairs[k] = v
}
}
m.logSpan(ctx, "MSet", strings.Join(keys, "||"))
return m.client.MSet(fixPairs...)
}

func (m *Client) GetBit(ctx context.Context, key string, offset int64) *redis.IntCmd {
k := m.fixKey(key)
m.logSpan(ctx, "GetBit", k)
Expand Down
Loading

0 comments on commit 0d83bbb

Please sign in to comment.