1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 08:32:40 +08:00
This commit is contained in:
2023-11-03 15:48:14 +08:00
parent 01f426c5b2
commit bdbf18969e
10 changed files with 93 additions and 33 deletions

View File

@ -7,10 +7,17 @@ import (
"sync"
"time"
_ "embed"
"github.com/charlienet/go-mixed/rand"
"github.com/charlienet/go-mixed/redis"
)
//go:embed redis_id_store.lua
var redis_id_function string
var once sync.Once
type redisStore struct {
rdb redis.Client
key string // 缓存键
@ -23,6 +30,8 @@ type redisStore struct {
}
func NewRedisStore(key string, rdb redis.Client) *redisStore {
once.Do(func() { rdb.LoadFunction(redis_id_function) })
return &redisStore{
rdb: rdb,
key: key,

View File

@ -10,16 +10,16 @@ import (
)
func TestSmallSerail(t *testing.T) {
tests.RunOnRedis(t, func(rdb redis.Client) {
tests.RunOnDefaultRedis(t, func(rdb redis.Client) {
s := store.NewRedisStore("sss", rdb)
for i := 0; i < 5; i++ {
t.Log(s.Assign(0, 9, 20))
}
}, redis.RedisOption{Addr: "192.168.123.50:6379", Password: "123456"})
})
}
func TestSmallAssign(t *testing.T) {
tests.RunOnRedis(t, func(rdb redis.Client) {
tests.RunOnDefaultRedis(t, func(rdb redis.Client) {
s := store.NewRedisStore("sss", rdb)
@ -27,11 +27,11 @@ func TestSmallAssign(t *testing.T) {
t.Log(s.Assign(0, 9, 30))
}
}, redis.RedisOption{Addr: "192.168.123.50:6379", Password: "123456"})
})
}
func TestBigAssign(t *testing.T) {
tests.RunOnRedis(t, func(rdb redis.Client) {
tests.RunOnDefaultRedis(t, func(rdb redis.Client) {
s := store.NewRedisStore("sss", rdb)
@ -39,11 +39,11 @@ func TestBigAssign(t *testing.T) {
t.Log(s.Assign(0, 99, 10))
}
}, redis.RedisOption{Addr: "192.168.123.50:6379", Password: "123456"})
})
}
func TestRedisAssign(t *testing.T) {
tests.RunOnRedis(t, func(rdb redis.Client) {
tests.RunOnDefaultRedis(t, func(rdb redis.Client) {
s := store.NewRedisStore("sss", rdb)
@ -51,11 +51,11 @@ func TestRedisAssign(t *testing.T) {
t.Log(s.Assign(21, 99, 30))
}
}, redis.RedisOption{Addr: "192.168.123.50:6379", Password: "123456"})
})
}
func TestFullRedisAssign(t *testing.T) {
tests.RunOnRedis(t, func(rdb redis.Client) {
tests.RunOnDefaultRedis(t, func(rdb redis.Client) {
s := store.NewRedisStore("sss", rdb)
@ -63,11 +63,11 @@ func TestFullRedisAssign(t *testing.T) {
t.Log(s.Assign(0, 999, 99))
}
}, redis.RedisOption{Addr: "192.168.123.50:6379", Password: "123456"})
})
}
func TestUpdateMachineCode(t *testing.T) {
tests.RunOnRedis(t, func(rdb redis.Client) {
tests.RunOnDefaultRedis(t, func(rdb redis.Client) {
for i := 0; i < 20; i++ {
s := store.NewRedisStore("id", rdb)
@ -85,7 +85,7 @@ func TestUpdateMachineCode(t *testing.T) {
time.Sleep(time.Second * 10)
}, redis.RedisOption{Addr: "192.168.123.50:6379", Password: "123456", Prefix: "cacc"})
})
}