-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f706c63
commit 05c26e8
Showing
12 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/infraboard/mcube/v2/ioc/config/cache" | ||
) | ||
|
||
type TestStruct struct { | ||
FiledA string | ||
} | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
c := cache.C() | ||
|
||
key := "test" | ||
obj := &TestStruct{FiledA: "test"} | ||
|
||
// 设置缓存 | ||
err := c.Set(ctx, key, obj, cache.WithExpiration(300)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// 后期缓存 | ||
var v *TestStruct | ||
err = c.Get(ctx, key, v) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/infraboard/mcube/v2/ioc/config/kafka" | ||
) | ||
|
||
func main() { | ||
// 消息生产者 | ||
producer := kafka.Producer("test") | ||
fmt.Println(producer) | ||
|
||
// 消息消费者 | ||
consumer := kafka.ConsumerGroup("group id", []string{"topic name"}) | ||
fmt.Println(consumer) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/infraboard/mcube/v2/ioc/config/lock" | ||
) | ||
|
||
func main() { | ||
// 创建一个key为test, 超时时间为10秒的锁 | ||
locker := lock.L().New("test", 10*time.Second) | ||
|
||
ctx := context.Background() | ||
|
||
// 获取锁 | ||
if err := locker.Lock(ctx); err != nil { | ||
panic(err) | ||
} | ||
|
||
// 释放锁 | ||
defer locker.UnLock(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/infraboard/mcube/v2/ioc/config/redis" | ||
) | ||
|
||
func main() { | ||
client := redis.Client() | ||
fmt.Println(client) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[cache] | ||
provider = "go_cache" | ||
ttl = 300 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[kafka] | ||
brokers = ["127.0.0.1:9092"] | ||
scram_algorithm = "SHA512" | ||
username = "" | ||
password = "" | ||
debug = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[lock] | ||
provider = "redis" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[redis] | ||
endpoints = ["127.0.0.1:6379"] | ||
database = 0 | ||
username = "" | ||
password = "" | ||
enable_trace = true | ||
enable_metrics = false |