diff --git a/common/db/redisproxy/redis.go b/common/db/redisproxy/redis.go index 1d19bfb..63359dd 100644 --- a/common/db/redisproxy/redis.go +++ b/common/db/redisproxy/redis.go @@ -36,6 +36,29 @@ func redisCommand(command string, args ...interface{}) (reply interface{}, err e return conn.Do(command , args...) } + +func ExpireKey(key interface{}, ttl interface{}) (reply interface{}, err error) { + return redisCommand("expire", key, ttl) +} + +//redis 管道操作 +func PipLine(f func(conn redis.Conn)) { + conn := RedisPool.Get() + defer conn.Close() + f(conn) +} + +func PipLineTest() { + PipLine(func(c redis.Conn) { + c.Send("SET", "foo", "bar") + c.Send("GET", "foo") + c.Flush() + //receive一次只从结果中拿出一个send的命令进行处理 + c.Receive() // reply from SET + _, _ = c.Receive() // reply from GET + }) +} + func SETNX(args ...interface{}) (reply interface{}, err error) { return redisCommand("SETNX", args...) } -- libgit2 0.21.2