Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5ad28c56
authored
Jul 01, 2025
by
hcy
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
336b9576
859c3e2d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
32 deletions
pkg/config/redis.go
pkg/gredis/redis.go
pkg/config/redis.go
View file @
5ad28c56
package
config
package
config
type
RedisDatabase
struct
{
type
RedisDatabase
struct
{
Password
string
Password
string
Host
string
Host
string
Database
string
Database
string
MaxIdle
int
MaxIdle
int
MaxActive
int
MaxActive
int
IdleTimeout
int
MaxAIdleTimeoutctive
string
MaxAIdleTimeoutctive
string
Prefix
string
Prefix
string
}
}
//多数据库配置
//
多数据库配置
func
BuildRedisConfigs
()
(
RedisDatabaseMap
map
[
string
]
RedisDatabase
)
{
func
BuildRedisConfigs
()
(
RedisDatabaseMap
map
[
string
]
RedisDatabase
)
{
redisReadMaxIdle
,
_
:=
Get
(
"default_redis_read.max_idle"
)
.
Int
()
redisReadMaxIdle
,
_
:=
Get
(
"default_redis_read.max_idle"
)
.
Int
()
redisReadMaxActive
,
_
:=
Get
(
"default_redis_read.max_active"
)
.
Int
()
redisReadMaxActive
,
_
:=
Get
(
"default_redis_read.max_active"
)
.
Int
()
redisWriteMaxIdle
,
_
:=
Get
(
"default_redis_write.max_idle"
)
.
Int
()
redisWriteMaxIdle
,
_
:=
Get
(
"default_redis_write.max_idle"
)
.
Int
()
redisWriteMaxActive
,
_
:=
Get
(
"default_redis_write.max_active"
)
.
Int
()
redisWriteMaxActive
,
_
:=
Get
(
"default_redis_write.max_active"
)
.
Int
()
redisSpuMaxIdle
,
_
:=
Get
(
"default_redis_spu.max_idle"
)
.
Int
()
redisSpuMaxIdle
,
_
:=
Get
(
"default_redis_spu.max_idle"
)
.
Int
()
redisSpuMaxActive
,
_
:=
Get
(
"default_redis_spu.max_active"
)
.
Int
()
redisSpuMaxActive
,
_
:=
Get
(
"default_redis_spu.max_active"
)
.
Int
()
redisIdleTimeout
,
_
:=
Get
(
"default_redis_read.idle_timeout"
)
.
Int
()
return
map
[
string
]
RedisDatabase
{
return
map
[
string
]
RedisDatabase
{
"search_r"
:
{
"search_r"
:
{
Host
:
Get
(
"default_redis_read.host"
)
.
String
(),
Host
:
Get
(
"default_redis_read.host"
)
.
String
(),
Password
:
Get
(
"default_redis_read.password"
)
.
String
(),
Password
:
Get
(
"default_redis_read.password"
)
.
String
(),
MaxIdle
:
redisReadMaxIdle
,
MaxIdle
:
redisReadMaxIdle
,
MaxActive
:
redisReadMaxActive
,
MaxActive
:
redisReadMaxActive
,
IdleTimeout
:
redisIdleTimeout
,
},
},
"default_r"
:
{
"default_r"
:
{
Host
:
Get
(
"default_redis_read.host"
)
.
String
(),
Host
:
Get
(
"default_redis_read.host"
)
.
String
(),
Password
:
Get
(
"default_redis_read.password"
)
.
String
(),
Password
:
Get
(
"default_redis_read.password"
)
.
String
(),
MaxIdle
:
redisReadMaxIdle
,
MaxIdle
:
redisReadMaxIdle
,
MaxActive
:
redisReadMaxActive
,
MaxActive
:
redisReadMaxActive
,
IdleTimeout
:
redisIdleTimeout
,
},
},
"search_w"
:
{
"search_w"
:
{
Host
:
Get
(
"default_redis_write.host"
)
.
String
(),
Host
:
Get
(
"default_redis_write.host"
)
.
String
(),
Password
:
Get
(
"default_redis_write.password"
)
.
String
(),
Password
:
Get
(
"default_redis_write.password"
)
.
String
(),
MaxIdle
:
redisWriteMaxIdle
,
MaxIdle
:
redisWriteMaxIdle
,
MaxActive
:
redisWriteMaxActive
,
MaxActive
:
redisWriteMaxActive
,
IdleTimeout
:
redisIdleTimeout
,
},
},
"spu"
:
{
"spu"
:
{
Host
:
Get
(
"default_redis_spu.host"
)
.
String
(),
Host
:
Get
(
"default_redis_spu.host"
)
.
String
(),
Password
:
Get
(
"default_redis_spu.password"
)
.
String
(),
Password
:
Get
(
"default_redis_spu.password"
)
.
String
(),
MaxIdle
:
redisSpuMaxIdle
,
MaxIdle
:
redisSpuMaxIdle
,
MaxActive
:
redisSpuMaxActive
,
MaxActive
:
redisSpuMaxActive
,
IdleTimeout
:
redisIdleTimeout
,
},
},
}
}
}
}
pkg/gredis/redis.go
View file @
5ad28c56
...
@@ -42,13 +42,15 @@ func getConn(writeHost, password string, maxIdle, maxActive int) (pool *redis.Po
...
@@ -42,13 +42,15 @@ func getConn(writeHost, password string, maxIdle, maxActive int) (pool *redis.Po
//maxIdle, _ := config.Get("redis.max_idle").Int()
//maxIdle, _ := config.Get("redis.max_idle").Int()
//maxActive, _ := config.Get("redis.max_active").Int()
//maxActive, _ := config.Get("redis.max_active").Int()
pool
=
&
redis
.
Pool
{
pool
=
&
redis
.
Pool
{
MaxIdle
:
maxIdle
,
MaxIdle
:
maxIdle
,
MaxActive
:
maxActive
,
MaxActive
:
maxActive
,
IdleTimeout
:
240
*
time
.
Second
,
Dial
:
func
()
(
redis
.
Conn
,
error
)
{
Dial
:
func
()
(
redis
.
Conn
,
error
)
{
c
,
err
:=
redis
.
Dial
(
"tcp"
,
writeHost
,
c
,
err
:=
redis
.
Dial
(
"tcp"
,
writeHost
,
redis
.
DialConnectTimeout
(
2
*
time
.
Second
),
redis
.
DialConnectTimeout
(
2
*
time
.
Second
),
redis
.
DialReadTimeout
(
2
*
time
.
Second
),
redis
.
DialReadTimeout
(
2
*
time
.
Second
),
redis
.
DialWriteTimeout
(
2
*
time
.
Second
))
redis
.
DialWriteTimeout
(
2
*
time
.
Second
),
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
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