Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
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-group
Commits
d6bed3fb
Commit
d6bed3fb
authored
Aug 30, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:user redis cluster
parent
75948b6a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
8 deletions
+10
-8
modelRedis.go
domain/cache/modelRedis.go
+4
-4
user.go
domain/cache/user_c/user.go
+4
-4
local.ini
local.ini
+2
-0
No files found.
domain/cache/modelRedis.go
View file @
d6bed3fb
...
@@ -27,7 +27,7 @@ func SetJSON(model *domain.Model, key string, obj interface{}) (err error) {
...
@@ -27,7 +27,7 @@ func SetJSON(model *domain.Model, key string, obj interface{}) (err error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
return
model
.
Redis
.
Set
(
model
.
Context
,
key
,
value
,
DEFAULT_TTL
)
.
Err
()
return
model
.
Redis
Cluster
.
Set
(
model
.
Context
,
key
,
value
,
DEFAULT_TTL
)
.
Err
()
}
}
// 获取redis中json结构体
// 获取redis中json结构体
...
@@ -37,7 +37,7 @@ func GetJSON(model *domain.Model, key string, obj interface{}) (err error) {
...
@@ -37,7 +37,7 @@ func GetJSON(model *domain.Model, key string, obj interface{}) (err error) {
defer
func
()
{
defer
func
()
{
model
.
Log
.
Infof
(
"GetJson key:%v,value:%s,obj:%v,err:%v"
,
key
,
value
,
obj
,
err
)
model
.
Log
.
Infof
(
"GetJson key:%v,value:%s,obj:%v,err:%v"
,
key
,
value
,
obj
,
err
)
}()
}()
value
,
err
=
model
.
Redis
.
Get
(
model
.
Context
,
key
)
.
Bytes
()
value
,
err
=
model
.
Redis
Cluster
.
Get
(
model
.
Context
,
key
)
.
Bytes
()
if
err
!=
nil
{
if
err
!=
nil
{
// may redisV2.Nil
// may redisV2.Nil
return
return
...
@@ -59,7 +59,7 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time
...
@@ -59,7 +59,7 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time
if
time
.
Now
()
.
After
(
deadline
)
{
if
time
.
Now
()
.
After
(
deadline
)
{
return
false
return
false
}
}
flag
,
err
:=
model
.
Redis
.
SetNX
(
model
,
key
,
"1"
,
expireTimeout
)
.
Result
()
flag
,
err
:=
model
.
Redis
Cluster
.
SetNX
(
model
,
key
,
"1"
,
expireTimeout
)
.
Result
()
if
err
!=
nil
||
!
flag
{
if
err
!=
nil
||
!
flag
{
time
.
Sleep
(
time
.
Millisecond
*
10
)
time
.
Sleep
(
time
.
Millisecond
*
10
)
}
else
{
}
else
{
...
@@ -70,5 +70,5 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time
...
@@ -70,5 +70,5 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time
// 解锁
// 解锁
func
UnLock
(
model
*
domain
.
Model
,
key
string
)
{
func
UnLock
(
model
*
domain
.
Model
,
key
string
)
{
model
.
Redis
.
Del
(
model
,
key
)
model
.
Redis
Cluster
.
Del
(
model
,
key
)
}
}
domain/cache/user_c/user.go
View file @
d6bed3fb
...
@@ -52,7 +52,7 @@ func ToUserId(model *domain.Model, externalId mysql.Str) (mysql.ID, error) {
...
@@ -52,7 +52,7 @@ func ToUserId(model *domain.Model, externalId mysql.Str) (mysql.ID, error) {
if
externalId
==
""
{
if
externalId
==
""
{
return
0
,
myerr
.
NewSysError
(
"externalId 不能为空"
)
return
0
,
myerr
.
NewSysError
(
"externalId 不能为空"
)
}
}
userId
,
err
:=
model
.
Redis
.
Get
(
model
.
Context
,
user_k
.
GetExternalIdToUidKey
(
externalId
))
.
Int64
()
userId
,
err
:=
model
.
Redis
Cluster
.
Get
(
model
.
Context
,
user_k
.
GetExternalIdToUidKey
(
externalId
))
.
Int64
()
if
err
!=
nil
&&
err
!=
redisV8
.
Nil
{
if
err
!=
nil
&&
err
!=
redisV8
.
Nil
{
return
0
,
err
return
0
,
err
}
}
...
@@ -75,7 +75,7 @@ func ToUserIdByCode(model *domain.Model, code mysql.Str) (mysql.ID, error) {
...
@@ -75,7 +75,7 @@ func ToUserIdByCode(model *domain.Model, code mysql.Str) (mysql.ID, error) {
if
code
==
""
{
if
code
==
""
{
return
0
,
myerr
.
NewSysError
(
"code 不能为空"
)
return
0
,
myerr
.
NewSysError
(
"code 不能为空"
)
}
}
userId
,
err
:=
model
.
Redis
.
Get
(
model
.
Context
,
user_k
.
GetCodeToUidKey
(
code
))
.
Int64
()
userId
,
err
:=
model
.
Redis
Cluster
.
Get
(
model
.
Context
,
user_k
.
GetCodeToUidKey
(
code
))
.
Int64
()
if
err
!=
nil
&&
err
!=
redisV8
.
Nil
{
if
err
!=
nil
&&
err
!=
redisV8
.
Nil
{
return
0
,
err
return
0
,
err
}
}
...
@@ -104,11 +104,11 @@ func cacheUserTiny(model *domain.Model, user *user_m.User) error {
...
@@ -104,11 +104,11 @@ func cacheUserTiny(model *domain.Model, user *user_m.User) error {
// return err
// return err
//}
//}
// cache externalId->userId
// cache externalId->userId
if
err
:=
model
.
Redis
.
SetEX
(
model
.
Context
,
user_k
.
GetExternalIdToUidKey
(
user
.
ExternalId
),
user
.
ID
,
cache
.
GetDefaultTTL
())
.
Err
();
err
!=
nil
{
if
err
:=
model
.
Redis
Cluster
.
SetEX
(
model
.
Context
,
user_k
.
GetExternalIdToUidKey
(
user
.
ExternalId
),
user
.
ID
,
cache
.
GetDefaultTTL
())
.
Err
();
err
!=
nil
{
return
err
return
err
}
}
// cache code->userId
// cache code->userId
if
err
:=
model
.
Redis
.
SetEX
(
model
.
Context
,
user_k
.
GetCodeToUidKey
(
user
.
Code
),
user
.
ID
,
cache
.
GetDefaultTTL
())
.
Err
();
err
!=
nil
{
if
err
:=
model
.
Redis
Cluster
.
SetEX
(
model
.
Context
,
user_k
.
GetCodeToUidKey
(
user
.
Code
),
user
.
ID
,
cache
.
GetDefaultTTL
())
.
Err
();
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
cache
.
SetJSON
(
model
,
user_k
.
GetUserTinyKey
(
user
.
ID
),
userTiny
);
err
!=
nil
{
if
err
:=
cache
.
SetJSON
(
model
,
user_k
.
GetUserTinyKey
(
user
.
ID
),
userTiny
);
err
!=
nil
{
...
...
local.ini
View file @
d6bed3fb
...
@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code
...
@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code
[REDIS]
[REDIS]
REDIS_HOST
=
47.244.34.27:6379
REDIS_HOST
=
47.244.34.27:6379
REDIS_PASSWORD
=
8QZ9JD1zLvPR3yHf
REDIS_PASSWORD
=
8QZ9JD1zLvPR3yHf
REDIS_CLUSTER_HOST
=
47.244.34.27:6379
REDIS_CLUSTER_PASSWORD
=
8QZ9JD1zLvPR3yHf
[JWT]
[JWT]
SECRET
=
hilo1632
SECRET
=
hilo1632
ISSUER_API
=
hiloApi
ISSUER_API
=
hiloApi
...
...
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