Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-micCenter
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-micCenter
Commits
7eea511f
Commit
7eea511f
authored
Sep 02, 2023
by
JiebinHu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
兼容新旧redis
parent
a37090f8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
0 deletions
+50
-0
redis.go
common/redisCli/redis.go
+20
-0
main.go
main.go
+30
-0
No files found.
common/redisCli/redis.go
View file @
7eea511f
...
...
@@ -9,6 +9,7 @@ import (
)
var
RedisCluster
*
redis
.
Client
var
RedisClient
*
redis
.
Client
func
init
()
{
RedisCluster
=
redis
.
NewClient
(
&
redis
.
Options
{
...
...
@@ -25,6 +26,21 @@ func init() {
}
else
{
log
.
Println
(
"redis db0 connection success - "
+
pong
)
}
RedisClient
=
redis
.
NewClient
(
&
redis
.
Options
{
Addr
:
config
.
GetConfigRedis
()
.
REDIS_HOST
,
Password
:
config
.
GetConfigRedis
()
.
REDIS_PASSWORD
,
// no password set
DB
:
0
,
// use default DB
PoolSize
:
200
,
MinIdleConns
:
20
,
})
pong
,
err
=
RedisClient
.
Ping
(
context
.
Background
())
.
Result
()
if
err
!=
nil
{
mylogrus
.
MyLog
.
Warn
(
err
)
mylogrus
.
MyLog
.
Fatal
(
"redis db0 connect fail"
)
}
else
{
log
.
Println
(
"redis db0 connection success - "
+
pong
)
}
// log hook
//RedisClient.AddHook(redisHook{})
}
...
...
@@ -32,3 +48,7 @@ func init() {
func
GetRedisCluster
()
*
redis
.
Client
{
return
RedisCluster
}
func
GetRedisClient
()
*
redis
.
Client
{
return
RedisClient
}
main.go
View file @
7eea511f
...
...
@@ -28,6 +28,9 @@ func main() {
go
func
()
{
deal
()
}()
go
func
()
{
dealOld
()
// 临时处理
}()
}
for
i
:=
0
;
i
<
SEND_WORKER
;
i
++
{
go
func
()
{
...
...
@@ -89,6 +92,33 @@ func deal() {
}
}
func
dealOld
()
{
for
true
{
//不需要加锁,注意,阻塞。
strs
,
err
:=
redisCli
.
GetRedisClient
()
.
BLPop
(
context
.
Background
(),
time
.
Second
,
micInfoChange
)
.
Result
()
if
err
!=
nil
{
if
err
!=
redis
.
Nil
{
mylogrus
.
MyLog
.
Errorf
(
"cron micChangeSys redisCli.GetRedis().BLPop err:+%v"
,
err
)
}
}
if
len
(
strs
)
>=
2
{
content
:=
strs
[
1
]
//mylogrus.MyLog.Infof("cron micChangeSys content:%v", content)
micSystemMsg
:=
MicSystemMsg
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
content
),
&
micSystemMsg
);
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"cron micChangeSys Unmarshal err:%+v, content:%v"
,
err
,
content
)
}
sendChan
<-
GroupSystemMsg
{
MsgGroupUid
:
micSystemMsg
.
GroupUid
,
MsgId
:
micSystemMsg
.
MsgId
,
Source
:
micSystemMsg
.
Source
,
Target
:
micSystemMsg
.
Target
,
Content
:
micSystemMsg
.
Content
,
}
}
}
}
//var limiter = rate.NewLimiter(2000, 2000)
func
send
()
{
...
...
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