채팅 채널 입장 추가
This commit is contained in:
@ -3,6 +3,7 @@ package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
@ -30,11 +31,46 @@ func TestPubSub(t *testing.T) {
|
||||
msg, err := pubsub.ReceiveMessage(context.Background())
|
||||
fmt.Println(msg.Payload, err)
|
||||
}
|
||||
func makeHash(chanName string, index uint32) string {
|
||||
for len(chanName) < 12 {
|
||||
chanName += chanName
|
||||
}
|
||||
left := chanName[:6]
|
||||
right := chanName[len(chanName)-6:]
|
||||
base := []byte(left + right)
|
||||
for i := 0; i < 12; i++ {
|
||||
base[i] += base[12-i-1]
|
||||
}
|
||||
|
||||
bs := make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(bs, index)
|
||||
for i, c := range bs {
|
||||
base[i] ^= c
|
||||
}
|
||||
var gid primitive.ObjectID
|
||||
copy(gid[:], base)
|
||||
|
||||
return gid.Hex()
|
||||
}
|
||||
|
||||
func TestNameHash(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
makeHash("Urud", uint32(i))
|
||||
fmt.Printf("Urud:%d - %s\n", i, makeHash("Urud", uint32(i)))
|
||||
makeHash("Sheldon", uint32(i))
|
||||
fmt.Printf("Sheldon:%d - %s\n", i, makeHash("Sheldon", uint32(i)))
|
||||
}
|
||||
}
|
||||
|
||||
func TestReJSON(t *testing.T) {
|
||||
rc := redis.NewClient(&redis.Options{Addr: "192.168.8.94:6380"})
|
||||
rh := gocommon.NewRedisonHandler(context.Background(), rc)
|
||||
|
||||
success, err := rc.HSetNX(context.Background(), "setnxtest", "cap", 100).Result()
|
||||
fmt.Println(success, err)
|
||||
success, err = rc.HSetNX(context.Background(), "setnxtest", "cap", 100).Result()
|
||||
fmt.Println(success, err)
|
||||
|
||||
testDoc := map[string]any{
|
||||
"members": map[string]any{
|
||||
"mid2": map[string]any{
|
||||
@ -64,7 +100,7 @@ func TestReJSON(t *testing.T) {
|
||||
logger.Println(rh.JSONGetInt64("jsontest", "$.members..exp"))
|
||||
logger.Println(rh.JSONObjKeys("jsontest", "$.members"))
|
||||
|
||||
err := rh.JSONMSet("jsontest", map[string]any{
|
||||
err = rh.JSONMSet("jsontest", map[string]any{
|
||||
"$.members.mid1.key": "newval",
|
||||
"$.members.mid2.key": "newval",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user