Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
3f91dfbc
Commit
3f91dfbc
authored
Oct 09, 2013
by
slene
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:astaxie/beego
parents
bf3830b6
bf836a21
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
12 deletions
+48
-12
cache.go
cache/cache.go
+4
-1
redis.go
cache/redis.go
+43
-11
router.go
router.go
+1
-0
No files found.
cache/cache.go
View file @
3f91dfbc
...
...
@@ -36,6 +36,9 @@ func NewCache(adapterName, config string) (Cache, error) {
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"cache: unknown adaptername %q (forgotten import?)"
,
adapterName
)
}
adapter
.
StartAndGC
(
config
)
err
:=
adapter
.
StartAndGC
(
config
)
if
err
!=
nil
{
return
nil
,
err
}
return
adapter
,
nil
}
cache/redis.go
View file @
3f91dfbc
...
...
@@ -22,7 +22,11 @@ func NewRedisCache() *RedisCache {
func
(
rc
*
RedisCache
)
Get
(
key
string
)
interface
{}
{
if
rc
.
c
==
nil
{
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
nil
}
}
v
,
err
:=
rc
.
c
.
Do
(
"HGET"
,
rc
.
key
,
key
)
if
err
!=
nil
{
...
...
@@ -33,7 +37,11 @@ func (rc *RedisCache) Get(key string) interface{} {
func
(
rc
*
RedisCache
)
Put
(
key
string
,
val
interface
{},
timeout
int64
)
error
{
if
rc
.
c
==
nil
{
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
err
}
}
_
,
err
:=
rc
.
c
.
Do
(
"HSET"
,
rc
.
key
,
key
,
val
)
return
err
...
...
@@ -41,7 +49,11 @@ func (rc *RedisCache) Put(key string, val interface{}, timeout int64) error {
func
(
rc
*
RedisCache
)
Delete
(
key
string
)
error
{
if
rc
.
c
==
nil
{
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
err
}
}
_
,
err
:=
rc
.
c
.
Do
(
"HDEL"
,
rc
.
key
,
key
)
return
err
...
...
@@ -49,7 +61,11 @@ func (rc *RedisCache) Delete(key string) error {
func
(
rc
*
RedisCache
)
IsExist
(
key
string
)
bool
{
if
rc
.
c
==
nil
{
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
false
}
}
v
,
err
:=
redis
.
Bool
(
rc
.
c
.
Do
(
"HEXISTS"
,
rc
.
key
,
key
))
if
err
!=
nil
{
...
...
@@ -60,7 +76,11 @@ func (rc *RedisCache) IsExist(key string) bool {
func
(
rc
*
RedisCache
)
Incr
(
key
string
)
error
{
if
rc
.
c
==
nil
{
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
err
}
}
_
,
err
:=
redis
.
Bool
(
rc
.
c
.
Do
(
"HINCRBY"
,
rc
.
key
,
key
,
1
))
if
err
!=
nil
{
...
...
@@ -71,7 +91,11 @@ func (rc *RedisCache) Incr(key string) error {
func
(
rc
*
RedisCache
)
Decr
(
key
string
)
error
{
if
rc
.
c
==
nil
{
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
err
}
}
_
,
err
:=
redis
.
Bool
(
rc
.
c
.
Do
(
"HINCRBY"
,
rc
.
key
,
key
,
-
1
))
if
err
!=
nil
{
...
...
@@ -82,7 +106,11 @@ func (rc *RedisCache) Decr(key string) error {
func
(
rc
*
RedisCache
)
ClearAll
()
error
{
if
rc
.
c
==
nil
{
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
err
}
}
_
,
err
:=
rc
.
c
.
Do
(
"DEL"
,
rc
.
key
)
return
err
...
...
@@ -99,19 +127,23 @@ func (rc *RedisCache) StartAndGC(config string) error {
}
rc
.
key
=
cf
[
"key"
]
rc
.
conninfo
=
cf
[
"conn"
]
rc
.
c
=
rc
.
connectInit
()
var
err
error
rc
.
c
,
err
=
rc
.
connectInit
()
if
err
!=
nil
{
return
err
}
if
rc
.
c
==
nil
{
return
errors
.
New
(
"dial tcp conn error"
)
}
return
nil
}
func
(
rc
*
RedisCache
)
connectInit
()
redis
.
Conn
{
func
(
rc
*
RedisCache
)
connectInit
()
(
redis
.
Conn
,
error
)
{
c
,
err
:=
redis
.
Dial
(
"tcp"
,
rc
.
conninfo
)
if
err
!=
nil
{
return
nil
return
nil
,
err
}
return
c
return
c
,
nil
}
func
init
()
{
...
...
router.go
View file @
3f91dfbc
...
...
@@ -300,6 +300,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
Output
:
beecontext
.
NewOutput
(
w
),
}
context
.
Output
.
Context
=
context
context
.
Output
.
EnableGzip
=
EnableGzip
if
context
.
Input
.
IsWebsocket
()
{
context
.
ResponseWriter
=
rw
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment