@@ -86,7 +86,7 @@ func AddGroup(group *Group, opts ...*SetOptions) (int64, error) {
86
86
group .ID = insertId
87
87
88
88
if opt .UpdateCache () {
89
- jcache .Set (GlobCtx , cacheKeyFormatGroupID (insertId ), group , jcache .DefaultExpirationDuration )
89
+ GlobCache .Set (GlobCtx , cacheKeyFormatGroupID (insertId ), group , jcache .DefaultExpirationDuration )
90
90
}
91
91
92
92
return insertId , nil
@@ -99,7 +99,7 @@ func GetGroup(id int64, opts ...*GetOptions) (*Group, error) {
99
99
if opt .UseCache () {
100
100
cacheKey := cacheKeyFormatGroupID (id )
101
101
group := new (Group )
102
- err := jcache .CheckAndScan (GlobCtx , group , cacheKey )
102
+ err := GlobCache .CheckAndScan (GlobCtx , group , cacheKey )
103
103
if err == nil {
104
104
return group , nil
105
105
}
@@ -118,7 +118,7 @@ func GetGroup(id int64, opts ...*GetOptions) (*Group, error) {
118
118
if errors .IsNoRecord (err ) {
119
119
// 写入缓存,如果key不存在的话
120
120
var cacheKey = cacheKeyFormatGroupID (id )
121
- if e := jcache .SetNX (GlobCtx , cacheKey , nil , jcache .DefaultEmptySetNXDuration ); e != nil {
121
+ if e := GlobCache .SetNX (GlobCtx , cacheKey , nil , jcache .DefaultEmptySetNXDuration ); e != nil {
122
122
log .Error ().Err (e ).Str ("err_format" , fmt .Sprintf ("%+v" , e )).Str ("cache_key" , cacheKey ).Msg ("缓存写入失败" )
123
123
}
124
124
}
@@ -127,7 +127,7 @@ func GetGroup(id int64, opts ...*GetOptions) (*Group, error) {
127
127
128
128
if opt .UpdateCache () {
129
129
cacheKey := cacheKeyFormatGroupID (id )
130
- jcache .Set (GlobCtx , cacheKey , group , jcache .RandomExpirationDuration ())
130
+ GlobCache .Set (GlobCtx , cacheKey , group , jcache .RandomExpirationDuration ())
131
131
}
132
132
133
133
return group , nil
@@ -193,7 +193,7 @@ func UpdateGroup(groupID int64, data *UpdateGroupData, opts ...*SetOptions) erro
193
193
194
194
defer func () {
195
195
if opt .UpdateCache () {
196
- jcache .Del (GlobCtx , cacheKeyFormatGroupID (groupID ))
196
+ GlobCache .Del (GlobCtx , cacheKeyFormatGroupID (groupID ))
197
197
}
198
198
}()
199
199
@@ -288,7 +288,7 @@ func AddGroupMembers(groupID int64, data *AddGroupMembersData, opts ...*SetOptio
288
288
return 0 , errors .Wrap (err )
289
289
}
290
290
if opt .UpdateCache () {
291
- jcache .Del (GlobCtx , cacheKeyFormatGroupMembers (groupID ))
291
+ GlobCache .Del (GlobCtx , cacheKeyFormatGroupMembers (groupID ))
292
292
}
293
293
294
294
rowsAffected , err := rs .RowsAffected ()
@@ -300,9 +300,9 @@ func GetGroupMemberCount(groupID int64, opts ...*GetOptions) (int64, error) {
300
300
opt := MergeGetOptions (opts )
301
301
if opt .UseCache () {
302
302
cacheKey := cacheKeyFormatGroupMembers (groupID )
303
- exists , _ := jcache .Exists (GlobCtx , cacheKey )
304
- if exists {
305
- cnt , err := jcache .HLen (GlobCtx , cacheKey )
303
+ exists , _ := GlobCache .Exists (GlobCtx , cacheKey )
304
+ if exists > 0 {
305
+ cnt , err := GlobCache .HLen (GlobCtx , cacheKey )
306
306
if err == nil {
307
307
return cnt , nil
308
308
}
@@ -324,9 +324,9 @@ func GetGroupMemberIDs(groupID int64, opts ...*GetOptions) ([]int64, error) {
324
324
var userIDs []int64
325
325
if opt .UseCache () {
326
326
cacheKey := cacheKeyFormatGroupMembers (groupID )
327
- exists , _ := jcache .Exists (GlobCtx , cacheKey )
328
- if exists {
329
- err := jcache .HKeysAndScan (GlobCtx , cacheKey , userIDs )
327
+ exists , _ := GlobCache .Exists (GlobCtx , cacheKey )
328
+ if exists > 0 {
329
+ err := GlobCache .HKeysAndScan (GlobCtx , userIDs , cacheKey )
330
330
if err == nil {
331
331
return userIDs , nil
332
332
}
@@ -359,9 +359,9 @@ func GetGroupMemberIDsString(groupID int64, opts ...*GetOptions) ([]string, erro
359
359
var userIDs []string
360
360
if opt .UseCache () {
361
361
cacheKey := cacheKeyFormatGroupMembers (groupID )
362
- exists , _ := jcache .Exists (GlobCtx , cacheKey )
363
- if exists {
364
- keys , err := jcache .HKeys (GlobCtx , cacheKey )
362
+ exists , _ := GlobCache .Exists (GlobCtx , cacheKey )
363
+ if exists > 0 {
364
+ keys , err := GlobCache .HKeys (GlobCtx , cacheKey )
365
365
if err == nil {
366
366
return keys , nil
367
367
}
@@ -433,7 +433,7 @@ func RemoveGroupMembers(filter *RemoveGroupMembersFilter, opts ...*SetOptions) (
433
433
for i := 0 ; i < len (membersIDs ); i ++ {
434
434
keys = append (keys , strconv .FormatInt (membersIDs [i ], 10 ))
435
435
}
436
- jcache .HDel (GlobCtx , cacheKeyFormatGroupMembers (groupID ), keys ... )
436
+ GlobCache .HDel (GlobCtx , cacheKeyFormatGroupMembers (groupID ), keys ... )
437
437
}
438
438
439
439
rowsAffected , err := rs .RowsAffected ()
@@ -446,9 +446,9 @@ func GetGroupAllMembers(groupID int64, opts ...*GetOptions) ([]*GroupMember, err
446
446
gms := make ([]* GroupMember , 0 )
447
447
if opt .UseCache () {
448
448
cacheKey := cacheKeyFormatGroupMembers (groupID )
449
- exists , _ := jcache .Exists (GlobCtx , cacheKey )
450
- if exists {
451
- err := jcache . HValsScan (GlobCtx , gms , cacheKeyFormatGroupMembers (groupID ))
449
+ exists , _ := GlobCache .Exists (GlobCtx , cacheKey )
450
+ if exists > 0 {
451
+ err := GlobCache . HValsAndScan (GlobCtx , gms , cacheKeyFormatGroupMembers (groupID ))
452
452
if err == nil {
453
453
return gms , nil
454
454
}
@@ -475,8 +475,8 @@ func GetGroupAllMembers(groupID int64, opts ...*GetOptions) ([]*GroupMember, err
475
475
m [strconv .FormatInt (gms [i ].UserID , 10 )] = gms [i ]
476
476
}
477
477
478
- jcache .HSet (GlobCtx , cacheKey , m )
479
- jcache .Expire (GlobCtx , cacheKey , jcache .RandomExpirationDuration ())
478
+ GlobCache .HSet (GlobCtx , cacheKey , m )
479
+ GlobCache .Expire (GlobCtx , cacheKey , jcache .RandomExpirationDuration ())
480
480
}
481
481
482
482
return gms , nil
@@ -488,14 +488,14 @@ func GetGroupMembers(groupID int64, memberIDs []int64, opts ...*GetOptions) ([]*
488
488
gms := make ([]* GroupMember , 0 )
489
489
if opt .UseCache () {
490
490
cacheKey := cacheKeyFormatGroupMembers (groupID )
491
- exists , _ := jcache .Exists (GlobCtx , cacheKey )
492
- if exists {
491
+ exists , _ := GlobCache .Exists (GlobCtx , cacheKey )
492
+ if exists > 0 {
493
493
var memberKeys = make ([]string , len (memberIDs ))
494
494
for i := 0 ; i < len (memberIDs ); i ++ {
495
495
memberKeys [i ] = fmt .Sprintf ("%d" , memberIDs [i ])
496
496
}
497
497
498
- err := jcache .HMGetAndScan (GlobCtx , gms , cacheKeyFormatGroupMembers (groupID ), memberKeys ... )
498
+ err := GlobCache .HMGetAndScan (GlobCtx , gms , cacheKeyFormatGroupMembers (groupID ), memberKeys ... )
499
499
if err == nil && len (gms ) == len (memberIDs ) {
500
500
return gms , nil
501
501
}
@@ -526,8 +526,8 @@ func GetGroupMembers(groupID int64, memberIDs []int64, opts ...*GetOptions) ([]*
526
526
m [strconv .FormatInt (gms [i ].UserID , 10 )] = gms [i ]
527
527
}
528
528
529
- jcache .HSet (GlobCtx , cacheKey , m )
530
- jcache .Expire (GlobCtx , cacheKey , jcache .RandomExpirationDuration ())
529
+ GlobCache .HSet (GlobCtx , cacheKey , m )
530
+ GlobCache .Expire (GlobCtx , cacheKey , jcache .RandomExpirationDuration ())
531
531
}
532
532
533
533
return gms , nil
@@ -539,9 +539,9 @@ func GetGroupMember(groupID, memberID int64, opts ...*GetOptions) (*GroupMember,
539
539
member := new (GroupMember )
540
540
if opt .UseCache () {
541
541
cacheKey := cacheKeyFormatGroupMembers (groupID )
542
- exists , _ := jcache .Exists (GlobCtx , cacheKey )
543
- if exists {
544
- err := jcache .HGetAndScan (GlobCtx , member , cacheKeyFormatGroupMembers (groupID ), fmt .Sprintf ("%d" , memberID ))
542
+ exists , _ := GlobCache .Exists (GlobCtx , cacheKey )
543
+ if exists > 0 {
544
+ err := GlobCache .HGetAndScan (GlobCtx , member , cacheKeyFormatGroupMembers (groupID ), fmt .Sprintf ("%d" , memberID ))
545
545
if err == nil {
546
546
return member , nil
547
547
}
@@ -558,8 +558,8 @@ func GetGroupMember(groupID, memberID int64, opts ...*GetOptions) (*GroupMember,
558
558
if opt .UpdateCache () {
559
559
cacheKey := cacheKeyFormatGroupMembers (groupID )
560
560
561
- if ok , _ := jcache .Exists (GlobCtx , cacheKey ); ok {
562
- jcache .HSet (GlobCtx , cacheKey , fmt .Sprintf ("%d" , memberID ), member )
561
+ if exists , _ := GlobCache .Exists (GlobCtx , cacheKey ); exists > 0 {
562
+ GlobCache .HSet (GlobCtx , cacheKey , fmt .Sprintf ("%d" , memberID ), member )
563
563
}
564
564
}
565
565
@@ -616,7 +616,7 @@ func UpdateGroupMember(groupID, userID int64, data *UpdateGroupMemberData, opts
616
616
617
617
if opt .UpdateCache () {
618
618
cacheKey := cacheKeyFormatGroupMembers (groupID )
619
- jcache .Del (GlobCtx , cacheKey )
619
+ GlobCache .Del (GlobCtx , cacheKey )
620
620
}
621
621
return nil
622
622
}
0 commit comments