stringx.go 661 B

12345678910111213141516171819202122232425262728
  1. package redisx
  2. import (
  3. "context"
  4. "time"
  5. )
  6. // 字符串操作封装
  7. func Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error {
  8. return getClient().Set(ctx, key, value, ttl).Err()
  9. }
  10. func Get(ctx context.Context, key string) (string, error) {
  11. return getClient().Get(ctx, key).Result()
  12. }
  13. func MSet(ctx context.Context, pairs ...interface{}) error {
  14. return getClient().MSet(ctx, pairs...).Err()
  15. }
  16. func MGet(ctx context.Context, keys ...string) ([]interface{}, error) {
  17. return getClient().MGet(ctx, keys...).Result()
  18. }
  19. func Incr(ctx context.Context, key string) (int64, error) {
  20. return getClient().Incr(ctx, key).Result()
  21. }