46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
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()
|
|
}
|