Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
a369b15e
authored
2014-01-09 18:49:18 +0800
by
Pengfei Xue
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
reset cache connection to nil, if err isio.EOF
* this will support auto-connection
1 parent
e34f8c46
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
6 deletions
cache/redis.go
cache/redis.go
View file @
a369b15
...
...
@@ -3,6 +3,7 @@ package cache
import
(
"encoding/json"
"errors"
"io"
"github.com/beego/redigo/redis"
)
...
...
@@ -33,10 +34,18 @@ func (rc *RedisCache) Get(key string) interface{} {
return
nil
}
}
v
,
err
:=
rc
.
c
.
Do
(
"HGET"
,
rc
.
key
,
key
)
// write to closed socket, reset rc.c to nil
if
err
==
io
.
EOF
{
rc
.
c
=
nil
return
nil
}
if
err
!=
nil
{
return
nil
}
return
v
}
...
...
@@ -50,7 +59,14 @@ func (rc *RedisCache) Put(key string, val interface{}, timeout int64) error {
return
err
}
}
_
,
err
:=
rc
.
c
.
Do
(
"HSET"
,
rc
.
key
,
key
,
val
)
// write to closed socket, reset rc.c to nil
if
err
==
io
.
EOF
{
rc
.
c
=
nil
return
err
}
return
err
}
...
...
@@ -63,7 +79,14 @@ func (rc *RedisCache) Delete(key string) error {
return
err
}
}
_
,
err
:=
rc
.
c
.
Do
(
"HDEL"
,
rc
.
key
,
key
)
// write to closed socket, reset rc.c to nil
if
err
==
io
.
EOF
{
rc
.
c
=
nil
return
err
}
return
err
}
...
...
@@ -76,10 +99,18 @@ func (rc *RedisCache) IsExist(key string) bool {
return
false
}
}
v
,
err
:=
redis
.
Bool
(
rc
.
c
.
Do
(
"HEXISTS"
,
rc
.
key
,
key
))
// write to closed socket, reset rc.c to nil
if
err
==
io
.
EOF
{
rc
.
c
=
nil
return
false
}
if
err
!=
nil
{
return
false
}
return
v
}
...
...
@@ -92,11 +123,14 @@ func (rc *RedisCache) Incr(key string) error {
return
err
}
}
_
,
err
:=
redis
.
Bool
(
rc
.
c
.
Do
(
"HINCRBY"
,
rc
.
key
,
key
,
1
))
if
err
!=
nil
{
return
err
// write to closed socket
if
err
==
io
.
EOF
{
rc
.
c
=
nil
}
return
nil
return
err
}
// decrease counter in redis.
...
...
@@ -108,11 +142,15 @@ func (rc *RedisCache) Decr(key string) error {
return
err
}
}
_
,
err
:=
redis
.
Bool
(
rc
.
c
.
Do
(
"HINCRBY"
,
rc
.
key
,
key
,
-
1
))
if
err
!=
nil
{
return
err
// write to closed socket
if
err
==
io
.
EOF
{
rc
.
c
=
nil
}
return
nil
return
err
}
// clean all cache in redis. delete this redis collection.
...
...
@@ -124,7 +162,13 @@ func (rc *RedisCache) ClearAll() error {
return
err
}
}
_
,
err
:=
rc
.
c
.
Do
(
"DEL"
,
rc
.
key
)
// write to closed socket
if
err
==
io
.
EOF
{
rc
.
c
=
nil
}
return
err
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment