redis操作
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
585 B

  1. package redis
  2. import (
  3. redisdb "github.com/gomodule/redigo/redis"
  4. )
  5. /**
  6. * 设置有效期
  7. */
  8. func SetExpire(key string, expire int64) (int64, error) {
  9. c := GetConn()
  10. var err error
  11. var reply interface{}
  12. reply, err = c.Do("expire", key, expire)
  13. CloseConn(c)
  14. if err != nil {
  15. return 0, err
  16. }
  17. return redisdb.Int64(reply, err)
  18. }
  19. /**
  20. * 获取有效期
  21. */
  22. func GetExpire(key string) (int64, error) {
  23. c := GetConn()
  24. var err error
  25. var reply interface{}
  26. reply, err = c.Do("TTL", key)
  27. CloseConn(c)
  28. if err != nil {
  29. return 0, err
  30. }
  31. return redisdb.Int64(reply, err)
  32. }