|
@@ -36,6 +36,7 @@ func TestGenCacheKeys(t *testing.T) {
|
|
}
|
|
}
|
|
primariCacheKey, uniqueCacheKey := genCacheKeys(parser.Table{
|
|
primariCacheKey, uniqueCacheKey := genCacheKeys(parser.Table{
|
|
Name: stringx.From("user"),
|
|
Name: stringx.From("user"),
|
|
|
|
+ Db: stringx.From("go_zero"),
|
|
PrimaryKey: parser.Primary{
|
|
PrimaryKey: parser.Primary{
|
|
Field: *primaryField,
|
|
Field: *primaryField,
|
|
AutoIncrement: true,
|
|
AutoIncrement: true,
|
|
@@ -70,14 +71,14 @@ func TestGenCacheKeys(t *testing.T) {
|
|
t.Run("primaryCacheKey", func(t *testing.T) {
|
|
t.Run("primaryCacheKey", func(t *testing.T) {
|
|
assert.Equal(t, true, func() bool {
|
|
assert.Equal(t, true, func() bool {
|
|
return cacheKeyEqual(primariCacheKey, Key{
|
|
return cacheKeyEqual(primariCacheKey, Key{
|
|
- VarLeft: "cacheUserIdPrefix",
|
|
|
|
- VarRight: `"cache:user:id:"`,
|
|
|
|
- VarExpression: `cacheUserIdPrefix = "cache:user:id:"`,
|
|
|
|
- KeyLeft: "userIdKey",
|
|
|
|
- KeyRight: `fmt.Sprintf("%s%v", cacheUserIdPrefix, id)`,
|
|
|
|
- DataKeyRight: `fmt.Sprintf("%s%v", cacheUserIdPrefix, data.Id)`,
|
|
|
|
- KeyExpression: `userIdKey := fmt.Sprintf("%s%v", cacheUserIdPrefix, id)`,
|
|
|
|
- DataKeyExpression: `userIdKey := fmt.Sprintf("%s%v", cacheUserIdPrefix, data.Id)`,
|
|
|
|
|
|
+ VarLeft: "cacheGoZeroUserIdPrefix",
|
|
|
|
+ VarRight: `"cache:goZero:user:id:"`,
|
|
|
|
+ VarExpression: `cacheGoZeroUserIdPrefix = "cache:goZero:user:id:"`,
|
|
|
|
+ KeyLeft: "goZeroUserIdKey",
|
|
|
|
+ KeyRight: `fmt.Sprintf("%s%v", cacheGoZeroUserIdPrefix, id)`,
|
|
|
|
+ DataKeyRight: `fmt.Sprintf("%s%v", cacheGoZeroUserIdPrefix, data.Id)`,
|
|
|
|
+ KeyExpression: `goZeroUserIdKey := fmt.Sprintf("%s%v", cacheGoZeroUserIdPrefix, id)`,
|
|
|
|
+ DataKeyExpression: `goZeroUserIdKey := fmt.Sprintf("%s%v", cacheGoZeroUserIdPrefix, data.Id)`,
|
|
FieldNameJoin: []string{"id"},
|
|
FieldNameJoin: []string{"id"},
|
|
})
|
|
})
|
|
}())
|
|
}())
|
|
@@ -87,25 +88,25 @@ func TestGenCacheKeys(t *testing.T) {
|
|
assert.Equal(t, true, func() bool {
|
|
assert.Equal(t, true, func() bool {
|
|
expected := []Key{
|
|
expected := []Key{
|
|
{
|
|
{
|
|
- VarLeft: "cacheUserClassNamePrefix",
|
|
|
|
- VarRight: `"cache:user:class:name:"`,
|
|
|
|
- VarExpression: `cacheUserClassNamePrefix = "cache:user:class:name:"`,
|
|
|
|
- KeyLeft: "userClassNameKey",
|
|
|
|
- KeyRight: `fmt.Sprintf("%s%v:%v", cacheUserClassNamePrefix, class, name)`,
|
|
|
|
- DataKeyRight: `fmt.Sprintf("%s%v:%v", cacheUserClassNamePrefix, data.Class, data.Name)`,
|
|
|
|
- KeyExpression: `userClassNameKey := fmt.Sprintf("%s%v:%v", cacheUserClassNamePrefix, class, name)`,
|
|
|
|
- DataKeyExpression: `userClassNameKey := fmt.Sprintf("%s%v:%v", cacheUserClassNamePrefix, data.Class, data.Name)`,
|
|
|
|
|
|
+ VarLeft: "cacheGoZeroUserClassNamePrefix",
|
|
|
|
+ VarRight: `"cache:goZero:user:class:name:"`,
|
|
|
|
+ VarExpression: `cacheGoZeroUserClassNamePrefix = "cache:goZero:user:class:name:"`,
|
|
|
|
+ KeyLeft: "goZeroUserClassNameKey",
|
|
|
|
+ KeyRight: `fmt.Sprintf("%s%v:%v", cacheGoZeroUserClassNamePrefix, class, name)`,
|
|
|
|
+ DataKeyRight: `fmt.Sprintf("%s%v:%v", cacheGoZeroUserClassNamePrefix, data.Class, data.Name)`,
|
|
|
|
+ KeyExpression: `goZeroUserClassNameKey := fmt.Sprintf("%s%v:%v", cacheGoZeroUserClassNamePrefix, class, name)`,
|
|
|
|
+ DataKeyExpression: `goZeroUserClassNameKey := fmt.Sprintf("%s%v:%v", cacheGoZeroUserClassNamePrefix, data.Class, data.Name)`,
|
|
FieldNameJoin: []string{"class", "name"},
|
|
FieldNameJoin: []string{"class", "name"},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- VarLeft: "cacheUserMobilePrefix",
|
|
|
|
- VarRight: `"cache:user:mobile:"`,
|
|
|
|
- VarExpression: `cacheUserMobilePrefix = "cache:user:mobile:"`,
|
|
|
|
- KeyLeft: "userMobileKey",
|
|
|
|
- KeyRight: `fmt.Sprintf("%s%v", cacheUserMobilePrefix, mobile)`,
|
|
|
|
- DataKeyRight: `fmt.Sprintf("%s%v", cacheUserMobilePrefix, data.Mobile)`,
|
|
|
|
- KeyExpression: `userMobileKey := fmt.Sprintf("%s%v", cacheUserMobilePrefix, mobile)`,
|
|
|
|
- DataKeyExpression: `userMobileKey := fmt.Sprintf("%s%v", cacheUserMobilePrefix, data.Mobile)`,
|
|
|
|
|
|
+ VarLeft: "cacheGoZeroUserMobilePrefix",
|
|
|
|
+ VarRight: `"cache:goZero:user:mobile:"`,
|
|
|
|
+ VarExpression: `cacheGoZeroUserMobilePrefix = "cache:goZero:user:mobile:"`,
|
|
|
|
+ KeyLeft: "goZeroUserMobileKey",
|
|
|
|
+ KeyRight: `fmt.Sprintf("%s%v", cacheGoZeroUserMobilePrefix, mobile)`,
|
|
|
|
+ DataKeyRight: `fmt.Sprintf("%s%v", cacheGoZeroUserMobilePrefix, data.Mobile)`,
|
|
|
|
+ KeyExpression: `goZeroUserMobileKey := fmt.Sprintf("%s%v", cacheGoZeroUserMobilePrefix, mobile)`,
|
|
|
|
+ DataKeyExpression: `goZeroUserMobileKey := fmt.Sprintf("%s%v", cacheGoZeroUserMobilePrefix, data.Mobile)`,
|
|
FieldNameJoin: []string{"mobile"},
|
|
FieldNameJoin: []string{"mobile"},
|
|
},
|
|
},
|
|
}
|
|
}
|