Browse Source

增加获取过期时间

master v1.7.0
guzeng 1 year ago
parent
commit
fc77d615ab
4 changed files with 59 additions and 1 deletions
  1. +17
    -0
      expire.go
  2. +24
    -0
      expire_test.go
  3. +1
    -1
      init.go
  4. +17
    -0
      string_test.go

+ 17
- 0
expire.go View File

@ -20,3 +20,20 @@ func SetExpire(key string, expire int64) (int64, error) {
}
return redisdb.Int64(reply, err)
}
/**
* 获取有效期
*/
func GetExpire(key string) (int64, error) {
c := GetConn()
var err error
var reply interface{}
reply, err = c.Do("TTL", key)
CloseConn(c)
if err != nil {
return 0, err
}
return redisdb.Int64(reply, err)
}

+ 24
- 0
expire_test.go View File

@ -0,0 +1,24 @@
package redis
import (
// "strconv"
"testing"
// "tgo/helper"
)
func Test_GetExpire(t *testing.T) {
RedisPassword = "123456"
RedisInit("127.0.0.1:6379", RedisPassword)
Set("test1", "sss")
ret3, err := SetExpire("test1", 10)
t.Log(ret3)
t.Log(err)
ret4, err := GetExpire("test1")
t.Log(ret4)
t.Log(err)
}

+ 1
- 1
init.go View File

@ -16,7 +16,7 @@ var RedisServerUrl string = "127.0.0.1:6379"
// redis密码,如需更改,在api服务中设置
var RedisPassword string = ""
var MaxActive, MaxIdle int
var MaxActive, MaxIdle int = 1, 1 //最大的激活连接数,最大的空闲连接数
// func init() {
// if Pool == nil {


+ 17
- 0
string_test.go View File

@ -0,0 +1,17 @@
package redis
import (
// "strconv"
"testing"
// "tgo/helper"
)
func Test_Exists(t *testing.T) {
RedisInit("127.0.0.1:6379", "123456")
ret3, err := Exists("60007_product")
t.Log(ret3)
t.Log(err)
}

Loading…
Cancel
Save