Commit 8f83d3226b416e7a6517346ace5492a00505f6b3
1 parent
29a163be
redis 管道操作
Showing
1 changed file
with
23 additions
and
0 deletions
Show diff stats
common/db/redisproxy/redis.go
@@ -36,6 +36,29 @@ func redisCommand(command string, args ...interface{}) (reply interface{}, err e | @@ -36,6 +36,29 @@ func redisCommand(command string, args ...interface{}) (reply interface{}, err e | ||
36 | return conn.Do(command , args...) | 36 | return conn.Do(command , args...) |
37 | } | 37 | } |
38 | 38 | ||
39 | + | ||
40 | +func ExpireKey(key interface{}, ttl interface{}) (reply interface{}, err error) { | ||
41 | + return redisCommand("expire", key, ttl) | ||
42 | +} | ||
43 | + | ||
44 | +//redis 管道操作 | ||
45 | +func PipLine(f func(conn redis.Conn)) { | ||
46 | + conn := RedisPool.Get() | ||
47 | + defer conn.Close() | ||
48 | + f(conn) | ||
49 | +} | ||
50 | + | ||
51 | +func PipLineTest() { | ||
52 | + PipLine(func(c redis.Conn) { | ||
53 | + c.Send("SET", "foo", "bar") | ||
54 | + c.Send("GET", "foo") | ||
55 | + c.Flush() | ||
56 | + //receive一次只从结果中拿出一个send的命令进行处理 | ||
57 | + c.Receive() // reply from SET | ||
58 | + _, _ = c.Receive() // reply from GET | ||
59 | + }) | ||
60 | +} | ||
61 | + | ||
39 | func SETNX(args ...interface{}) (reply interface{}, err error) { | 62 | func SETNX(args ...interface{}) (reply interface{}, err error) { |
40 | return redisCommand("SETNX", args...) | 63 | return redisCommand("SETNX", args...) |
41 | } | 64 | } |