diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-07-31 08:15:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-31 08:15:23 -0700 |
commit | 09b49c26ddfdb20ced61e7dfd4192e750ce40449 (patch) | |
tree | 1288d069cc8a199b8eb3b858935dffd377ee3d2d /vendor/github.com/go-redis/redis/internal/pool/conn.go | |
parent | 6f4e38d129ffaf469d40fc8596d3957ee94d21e9 (diff) | |
download | chat-09b49c26ddfdb20ced61e7dfd4192e750ce40449.tar.gz chat-09b49c26ddfdb20ced61e7dfd4192e750ce40449.tar.bz2 chat-09b49c26ddfdb20ced61e7dfd4192e750ce40449.zip |
PLT-5308 Caching layer part 2 (#6973)
* Adding Reaction store cache layer example
* Implementing reaction store in new caching system.
* Redis for reaction store
* Adding redis library
* Adding invalidation for DeleteAllWithEmojiName and other minor enhancements
Diffstat (limited to 'vendor/github.com/go-redis/redis/internal/pool/conn.go')
-rw-r--r-- | vendor/github.com/go-redis/redis/internal/pool/conn.go | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/vendor/github.com/go-redis/redis/internal/pool/conn.go b/vendor/github.com/go-redis/redis/internal/pool/conn.go new file mode 100644 index 000000000..8af51d9de --- /dev/null +++ b/vendor/github.com/go-redis/redis/internal/pool/conn.go @@ -0,0 +1,78 @@ +package pool + +import ( + "net" + "sync/atomic" + "time" + + "github.com/go-redis/redis/internal/proto" +) + +var noDeadline = time.Time{} + +type Conn struct { + netConn net.Conn + + Rd *proto.Reader + Wb *proto.WriteBuffer + + Inited bool + usedAt atomic.Value +} + +func NewConn(netConn net.Conn) *Conn { + cn := &Conn{ + netConn: netConn, + Wb: proto.NewWriteBuffer(), + } + cn.Rd = proto.NewReader(cn.netConn) + cn.SetUsedAt(time.Now()) + return cn +} + +func (cn *Conn) UsedAt() time.Time { + return cn.usedAt.Load().(time.Time) +} + +func (cn *Conn) SetUsedAt(tm time.Time) { + cn.usedAt.Store(tm) +} + +func (cn *Conn) SetNetConn(netConn net.Conn) { + cn.netConn = netConn + cn.Rd.Reset(netConn) +} + +func (cn *Conn) IsStale(timeout time.Duration) bool { + return timeout > 0 && time.Since(cn.UsedAt()) > timeout +} + +func (cn *Conn) SetReadTimeout(timeout time.Duration) error { + now := time.Now() + cn.SetUsedAt(now) + if timeout > 0 { + return cn.netConn.SetReadDeadline(now.Add(timeout)) + } + return cn.netConn.SetReadDeadline(noDeadline) +} + +func (cn *Conn) SetWriteTimeout(timeout time.Duration) error { + now := time.Now() + cn.SetUsedAt(now) + if timeout > 0 { + return cn.netConn.SetWriteDeadline(now.Add(timeout)) + } + return cn.netConn.SetWriteDeadline(noDeadline) +} + +func (cn *Conn) Write(b []byte) (int, error) { + return cn.netConn.Write(b) +} + +func (cn *Conn) RemoteAddr() net.Addr { + return cn.netConn.RemoteAddr() +} + +func (cn *Conn) Close() error { + return cn.netConn.Close() +} |