1 Star 1 Fork 0

orbit/meteor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
redis_key.go 899 Bytes
一键复制 编辑 原始数据 按行查看 历史
package storage
import (
"fmt"
"hash/fnv"
"strconv"
"strings"
)
// generateKey creates a unique Redis key for an entity
func GenerateKey(pattern, uuid string) string {
return fmt.Sprintf("%s:%s", pattern, uuid)
}
func GenerateIndexKey(key string) string {
shardID := getSharedId(key)
return RedisIndexKeyPrefix + strconv.FormatUint(uint64(shardID), 10)
}
func ParseKey(key string) (string, string) {
parts := strings.Split(key, ":")
if len(parts) != 2 {
return "", ""
}
return parts[0], parts[1]
}
func GenQueueKey(key string) string {
shardID := getSharedId(key)
return RedisListKeyPrefix + strconv.FormatUint(uint64(shardID), 10)
}
func GenQueueKeyByShardId(shardID uint32) string {
return RedisListKeyPrefix + strconv.FormatUint(uint64(shardID), 10)
}
func getSharedId(key string) uint32 {
h := fnv.New32a()
h.Write([]byte(key))
return h.Sum32() % RedisListShardCount
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/orbit-w/meteor.git
git@gitee.com:orbit-w/meteor.git
orbit-w
meteor
meteor
8cff0bb952fe

搜索帮助