diff --git a/expire.go b/expire.go index 1529dc2..5e86b9a 100644 --- a/expire.go +++ b/expire.go @@ -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) +} diff --git a/expire_test.go b/expire_test.go new file mode 100644 index 0000000..d0e388a --- /dev/null +++ b/expire_test.go @@ -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) + +} diff --git a/init.go b/init.go index eaed7a4..716e4aa 100644 --- a/init.go +++ b/init.go @@ -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 { diff --git a/string_test.go b/string_test.go new file mode 100644 index 0000000..aef07d9 --- /dev/null +++ b/string_test.go @@ -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) + +}