stringx.go 768 B

1234567891011121314151617181920212223242526272829303132
  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. }
  22. func Decr(ctx context.Context, key string) (int64, error) {
  23. return getClient().Decr(ctx, key).Result()
  24. }