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
75948b6a
Commit
75948b6a
authored
Aug 30, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:国旗,国家位置
parent
55ac5ee5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
20 deletions
+36
-20
country.go
domain/cache/res_c/country.go
+36
-20
No files found.
domain/cache/res_c/country.go
View file @
75948b6a
package
res_c
import
(
"context"
"git.hilo.cn/hilo-common/domain"
"
hilo-group/_const/redis_key
"
"
github.com/bluele/gcache
"
"hilo-group/domain/model/res_m"
"time"
)
// 统一改成lru
var
countryIconLru
=
gcache
.
New
(
1000
)
.
LRU
()
.
Build
()
var
countryIconKey
=
"country:icon"
var
countryAreaLru
=
gcache
.
New
(
1000
)
.
LRU
()
.
Build
()
var
countryAreaKey
=
"country:area"
func
GetCountryIconMap
(
model
*
domain
.
Model
)
(
map
[
string
]
string
,
error
)
{
m
,
err
:=
GetAllCountryIcon
(
model
)
if
err
!=
nil
||
len
(
m
)
<=
0
{
...
...
@@ -24,17 +30,22 @@ func GetCountryIconMap(model *domain.Model) (map[string]string, error) {
}
func
GetAllCountryIcon
(
model
*
domain
.
Model
)
(
map
[
string
]
string
,
error
)
{
key
:=
redis_key
.
GetCountryIconKey
()
return
model
.
Redis
.
HGetAll
(
context
.
Background
(),
key
)
.
Result
()
//key := redis_key.GetCountryIconKey()
if
data
,
err
:=
countryIconLru
.
Get
(
countryIconKey
);
err
==
nil
{
return
data
.
(
map
[
string
]
string
),
nil
}
//return model.Redis.HGetAll(context.Background(), key).Result()
return
map
[
string
]
string
{},
nil
}
func
SaveAllCountryIcon
(
model
*
domain
.
Model
,
icons
map
[
string
]
string
)
(
int64
,
error
)
{
key
:=
redis_key
.
GetCountryIconKey
()
ret
,
err
:=
model
.
Redis
.
HSet
(
context
.
Background
(),
key
,
icons
)
.
Result
()
if
err
==
nil
{
model
.
Redis
.
Expire
(
context
.
Background
(),
key
,
time
.
Minute
*
10
)
}
return
ret
,
err
func
SaveAllCountryIcon
(
model
*
domain
.
Model
,
icons
map
[
string
]
string
)
{
//key := redis_key.GetCountryIconKey()
//ret, err := model.Redis.HSet(context.Background(), key, icons).Result()
//if err == nil {
// model.Redis.Expire(context.Background(), key, time.Minute*10)
//}
//return ret, err
_
=
countryIconLru
.
SetWithExpire
(
countryIconKey
,
icons
,
time
.
Minute
*
10
)
}
func
GetCountryAreaMap
(
model
*
domain
.
Model
)
(
map
[
string
]
string
,
error
)
{
...
...
@@ -53,15 +64,20 @@ func GetCountryAreaMap(model *domain.Model) (map[string]string, error) {
}
func
GetAllCountryArea
(
model
*
domain
.
Model
)
(
map
[
string
]
string
,
error
)
{
key
:=
redis_key
.
GetCountryAreaKey
()
return
model
.
Redis
.
HGetAll
(
context
.
Background
(),
key
)
.
Result
()
//key := redis_key.GetCountryAreaKey()
//return model.Redis.HGetAll(context.Background(), key).Result()
if
data
,
err
:=
countryAreaLru
.
Get
(
countryAreaKey
);
err
==
nil
{
return
data
.
(
map
[
string
]
string
),
nil
}
return
map
[
string
]
string
{},
nil
}
func
SaveAllCountryArea
(
model
*
domain
.
Model
,
data
map
[
string
]
string
)
(
int64
,
error
)
{
key
:=
redis_key
.
GetCountryAreaKey
()
ret
,
err
:=
model
.
Redis
.
HSet
(
context
.
Background
(),
key
,
data
)
.
Result
()
if
err
==
nil
{
model
.
Redis
.
Expire
(
context
.
Background
(),
key
,
time
.
Minute
*
10
)
}
return
ret
,
err
func
SaveAllCountryArea
(
model
*
domain
.
Model
,
data
map
[
string
]
string
)
{
//key := redis_key.GetCountryAreaKey()
//ret, err := model.Redis.HSet(context.Background(), key, data).Result()
//if err == nil {
// model.Redis.Expire(context.Background(), key, time.Minute*10)
//}
//return ret, err
_
=
countryAreaLru
.
SetWithExpire
(
countryAreaKey
,
data
,
time
.
Minute
*
10
)
}
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