Skip to content

Commit 6597efc

Browse files
committed
backup
1 parent eadc5b1 commit 6597efc

File tree

6 files changed

+105
-13
lines changed

6 files changed

+105
-13
lines changed

MyStruct/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
RM ?= rm -rf
2+
GOBUILD = go build
3+
GOTEST = go test # -v
4+
5+
VARS=vars.mk
6+
$(shell ./build_config ${VARS})
7+
include ${VARS}
8+
9+
.PHONY: test clean build
10+
11+
build:
12+
@cd bin/ && ${GOBUILD} Main && cd ..
13+
14+
test:
15+
@cd src/FreqCtrl/ && ${GOTEST} && cd ../..
16+
17+
bench:
18+
@cd src/FreqCtrl/ && ${GOTEST} -bench=. && cd ../..
19+
20+
clean:
21+
${RM} ${VARS} bin/*

MyStruct/MyStruct/struct.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package MyStruct
2+
3+
type Conn struct{
4+
c int
5+
a int
6+
CC int
7+
AA int
8+
}

MyStruct/build_config

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
OUTPUT=$1
4+
PWD=$(pwd)
5+
6+
if test -z "${OUTPUT}"; then
7+
echo "Usage: $0 <output_file>"
8+
exit 1
9+
fi
10+
11+
rm -f ${OUTPUT}
12+
touch ${OUTPUT}
13+
14+
if [ ! -d "bin" ]; then
15+
$(mkdir bin)
16+
fi
17+
18+
echo "GOPATH=${GOPATH}:${PWD}" >> ${OUTPUT}

MyStruct/vars.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GOPATH=/usr/local/godown:/home/yang/Work/GolangCode/FreqCtrl

conn.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package redistest
2+
3+
import (
4+
"github.com/garyburd/redigo/redis"
5+
)
6+
7+
//var conn redis.Conn
8+
func newPool() *redis.Pool {
9+
return &redis.Pool{
10+
MaxIdle: 80,
11+
MaxActive: 200,
12+
Dial: func() (redis.Conn, error) {
13+
c, err := redis.Dial("tcp", "localhost:6379")
14+
if err != nil {
15+
panic(err.Error())
16+
}
17+
return c, err
18+
},
19+
}
20+
}
21+
22+
var pool = newPool()
23+
24+
/*
25+
func Init()error{
26+
pool = newPool()
27+
}
28+
*/
29+
30+
func getConn() redis.Pool {
31+
c := pool.Get()
32+
return c
33+
}
34+
35+
func (c *redis.Pool) releaseConn() {
36+
c.Close()
37+
}
38+
39+
func DoGet(userId string) {
40+
c := getConn()
41+
defer c.releaseConn()
42+
}
43+
44+
func PipeGet(userId string) {
45+
}
46+
func Release() {
47+
}

redis_test/conn.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"github.com/garyburd/redigo/redis"
55
)
66

7-
//var conn redis.Conn
87
func newPool() *redis.Pool {
98
return &redis.Pool{
109
MaxIdle: 80,
@@ -21,29 +20,27 @@ func newPool() *redis.Pool {
2120

2221
var pool = newPool()
2322

24-
/*
25-
func Init()error{
26-
pool = newPool()
27-
}
28-
*/
29-
3023
func getConn() redis.Conn {
3124
c := pool.Get()
3225
return c
3326
}
3427

35-
func releaseConn(c *redis.Conn) {
36-
(*c).Close()
28+
func releaseConn() error {
29+
return nil
3730
}
3831

3932
func DoGet(userId string) {
40-
c := getConn()
33+
c := pool.Get()
4134
c.Do("INCR", userId)
42-
c.Close()
35+
defer c.Close()
36+
}
37+
38+
func GetActiveConnNum() int {
39+
return pool.ActiveCount()
4340
}
4441

4542
func PipeGet(userId string) {
46-
c := getConn()
43+
c := pool.Get()
4744
c.Send("INCR", userId)
48-
c.Close()
45+
defer c.Close()
4946
}

0 commit comments

Comments
 (0)