finclip-app-manager/vendor/gitlab.finogeeks.club/finclip-backend-v2/finclip-redis/randcommand.go

46 lines
1.1 KiB
Go
Raw Normal View History

2023-11-02 18:36:36 +08:00
package fcredis
import (
"context"
"time"
)
// RandSet Zero expiration means the key has no expiration time.
func RandSet(ctx context.Context, key string, value interface{}, expiration time.Duration) error {
desKeys := GetRandKeys(key)
for _, k := range desKeys {
err := gUniClient.Set(ctx, k, value, expiration).Err()
if err != nil {
return err
}
}
return nil
}
func RandDel(ctx context.Context, key string) error {
desKeys := GetRandKeys(key)
for _, k := range desKeys {
err := gUniClient.Del(ctx, k).Err()
if err != nil {
return err
}
}
return nil
}
func RandSetBytes(ctx context.Context, key string, value []byte, expiration time.Duration) error {
return RandSet(ctx, key, string(value), expiration)
}
func RandGet(ctx context.Context, key string) (string, error) {
return get(ctx, GetRandKey(key)).Result()
}
func RandGetBytes(ctx context.Context, key string) ([]byte, error) {
return get(ctx, GetRandKey(key)).Bytes()
}
func RandGetString(ctx context.Context, key string) (string, error) {
return get(ctx, GetRandKey(key)).Result()
}