Compare commits
6 Commits
1c56423ea4
...
main
Author | SHA1 | Date | |
---|---|---|---|
0992b02880 | |||
1f8a5b8c37 | |||
795a9186a9 | |||
69d4c5d038 | |||
78d496ae72 | |||
4c19f4b16c |
@@ -12,6 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ReadDataHandler(c *gin.Context) {
|
func ReadDataHandler(c *gin.Context) {
|
||||||
|
//解析输入数据
|
||||||
input := struct {
|
input := struct {
|
||||||
Token string `form:"token" binding:"required"`
|
Token string `form:"token" binding:"required"`
|
||||||
}{}
|
}{}
|
||||||
@@ -20,12 +21,11 @@ func ReadDataHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
lLen := global.RDB.LLen(global.RCtx, fmt.Sprintf("list:%s", input.Token))
|
retData := global.RDB.LPop(global.RCtx, fmt.Sprintf("list:%s", input.Token)).Val()
|
||||||
if lLen.Val() == 0 {
|
if retData == "null" {
|
||||||
c.JSON(http.StatusOK, gin.H{"result": "数据库没有数据"})
|
c.JSON(http.StatusOK, gin.H{"result": "数据库没有数据"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
retData := global.RDB.BLPop(global.RCtx, 0, fmt.Sprintf("list:%s", input.Token)).Val()[1]
|
|
||||||
|
|
||||||
c.String(http.StatusOK, retData)
|
c.String(http.StatusOK, retData)
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ func WriteDataHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
dedupValue := strings.Split(input.Data, "----")[dataIndex[dedupObject]]
|
dedupValue := strings.Split(input.Data, "----")[dataIndex[dedupObject]]
|
||||||
|
|
||||||
err = createCF(fmt.Sprintf("dedup:%s:%s", input.Token, dedupObject), 100000000)
|
err = createCF(fmt.Sprintf("dedup:%s:%s", input.Token, dedupObject), 100_000_000)
|
||||||
if err != nil && err.Error() != "ERR item exists" {
|
if err != nil && err.Error() != "ERR item exists" {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
@@ -62,6 +62,7 @@ func WriteDataHandler(c *gin.Context) {
|
|||||||
luaScript := `
|
luaScript := `
|
||||||
local dedupKey = KEYS[1] -- KEYS[1]: 去重键 (dedup:token:object)
|
local dedupKey = KEYS[1] -- KEYS[1]: 去重键 (dedup:token:object)
|
||||||
local listKey = KEYS[2] -- KEYS[2]: 列表键 (list:token)
|
local listKey = KEYS[2] -- KEYS[2]: 列表键 (list:token)
|
||||||
|
local deleteListKey = KEYS[3] -- KEYS[3]: 删除列表键 (delete-list:token)
|
||||||
local dedupValue = ARGV[1] -- ARGV[1]: 去重值
|
local dedupValue = ARGV[1] -- ARGV[1]: 去重值
|
||||||
local rawData = ARGV[2] -- ARGV[2]: 原始数据
|
local rawData = ARGV[2] -- ARGV[2]: 原始数据
|
||||||
|
|
||||||
@@ -78,6 +79,8 @@ redis.call('CF.ADD', dedupKey, dedupValue)
|
|||||||
-- 添加到列表
|
-- 添加到列表
|
||||||
redis.call('LPUSH', listKey, rawData)
|
redis.call('LPUSH', listKey, rawData)
|
||||||
|
|
||||||
|
redis.call('LPUSH', deleteListKey, dedupValue)
|
||||||
|
|
||||||
-- 返回成功结果
|
-- 返回成功结果
|
||||||
return "ok"
|
return "ok"
|
||||||
`
|
`
|
||||||
@@ -87,6 +90,7 @@ return "ok"
|
|||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("dedup:%s:%s", input.Token, dedupObject),
|
fmt.Sprintf("dedup:%s:%s", input.Token, dedupObject),
|
||||||
fmt.Sprintf("list:%s", input.Token),
|
fmt.Sprintf("list:%s", input.Token),
|
||||||
|
fmt.Sprintf("delete-list:%s", input.Token),
|
||||||
},
|
},
|
||||||
dedupValue,
|
dedupValue,
|
||||||
input.Data,
|
input.Data,
|
||||||
@@ -105,7 +109,7 @@ return "ok"
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createCF(bloomFilter string, capacity int64) error {
|
func createCF(bloomFilter string, capacity int64) error {
|
||||||
_, err := global.RDB.CFReserve(global.RCtx, bloomFilter, capacity).Result()
|
_, err := global.RDB.CFReserveBucketSize(global.RCtx, bloomFilter, capacity, 6).Result()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,9 +5,9 @@ import (
|
|||||||
"dypid/global"
|
"dypid/global"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ListTokenHandler(c *gin.Context) {
|
func ListTokenHandler(c *gin.Context) {
|
||||||
@@ -107,7 +107,7 @@ func GetTokenInfoHandler(c *gin.Context) {
|
|||||||
output.Token = input.Token
|
output.Token = input.Token
|
||||||
output.DedupObject = dedupObject
|
output.DedupObject = dedupObject
|
||||||
output.DataFormat = dataFormat
|
output.DataFormat = dataFormat
|
||||||
output.DedupItemsNumber = global.RDB.BFCard(global.RCtx, "dedup:"+input.Token+":"+dedupObject).Val()
|
output.DedupItemsNumber = global.RDB.CFInfo(global.RCtx, "dedup:"+input.Token+":"+dedupObject).Val().NumItemsInserted
|
||||||
output.CacheListNumber = global.RDB.LLen(global.RCtx, "list:"+input.Token).Val()
|
output.CacheListNumber = global.RDB.LLen(global.RCtx, "list:"+input.Token).Val()
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"result": output})
|
c.JSON(http.StatusOK, gin.H{"result": output})
|
||||||
@@ -132,7 +132,6 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
|||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Token不存在" + err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Token不存在" + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dedupObject, err := db.GetDedupObject(input.Token)
|
dedupObject, err := db.GetDedupObject(input.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
@@ -145,14 +144,28 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
|||||||
case "all":
|
case "all":
|
||||||
keys := global.RDB.Keys(global.RCtx, "dedup:"+input.Token+":*").Val()
|
keys := global.RDB.Keys(global.RCtx, "dedup:"+input.Token+":*").Val()
|
||||||
global.RDB.Del(global.RCtx, keys...)
|
global.RDB.Del(global.RCtx, keys...)
|
||||||
|
global.RDB.Del(global.RCtx, "delete-list:"+input.Token)
|
||||||
default:
|
default:
|
||||||
//TODO 不考虑单独删除指定数量去重参考值
|
i, err := strconv.Atoi(input.DedupBF)
|
||||||
_, err := strconv.Atoi(input.DedupBF)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_bf设置错误 " + err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_bf设置错误 " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
result := global.RDB.LRange(global.RCtx, "delete-list:"+input.Token, int64(-i), -1).Val()
|
||||||
|
_, err = global.RDB.TxPipelined(global.RCtx, func(pipe redis.Pipeliner) error {
|
||||||
|
for _, s := range result {
|
||||||
|
pipe.CFDel(global.RCtx, "dedup:"+input.Token+":"+dedupObject, s)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
global.RDB.LTrim(global.RCtx, "delete-list:"+input.Token, 0, int64(-i-1))
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除原始数据
|
||||||
switch input.CacheList {
|
switch input.CacheList {
|
||||||
case "":
|
case "":
|
||||||
case "all":
|
case "all":
|
||||||
@@ -163,9 +176,11 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "cache_list设置错误 " + err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "cache_list设置错误 " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
global.RDB.LTrim(global.RCtx, "list:"+input.Token, 1, int64(-i))
|
|
||||||
|
global.RDB.LTrim(global.RCtx, "list:"+input.Token, 0, int64(-i-1))
|
||||||
}
|
}
|
||||||
//TODO
|
|
||||||
|
//删除去重参考值和原始数据
|
||||||
switch input.BothNumber {
|
switch input.BothNumber {
|
||||||
case "":
|
case "":
|
||||||
default:
|
default:
|
||||||
@@ -174,12 +189,19 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "both_number设置错误 " + err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "both_number设置错误 " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := global.RDB.LRange(global.RCtx, "list:"+input.Token, 1, int64(i)).Val()
|
|
||||||
global.RDB.LTrim(global.RCtx, "list:"+input.Token, 1, int64(-i))
|
result := global.RDB.LRange(global.RCtx, "delete-list:"+input.Token, int64(-i), -1).Val()
|
||||||
dataIndex, err := getDataIndex(input.Token)
|
_, err = global.RDB.TxPipelined(global.RCtx, func(pipe redis.Pipeliner) error {
|
||||||
for _, s := range result {
|
for _, s := range result {
|
||||||
s2 := strings.Split(s, "----")[dataIndex[dedupObject]]
|
pipe.CFDel(global.RCtx, "dedup:"+input.Token+":"+dedupObject, s)
|
||||||
global.RDB.CFDel(global.RCtx, "dedup:"+input.Token+":"+dedupObject, s2)
|
}
|
||||||
|
pipe.LTrim(global.RCtx, "delete-list:"+input.Token, 0, int64(-i-1))
|
||||||
|
pipe.LTrim(global.RCtx, "list:"+input.Token, 0, int64(-i-1))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,7 +54,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
fmt.Println("上传完成,耗时:", time.Since(start))
|
fmt.Printf("上传完成,耗时:%s\n", time.Since(start))
|
||||||
}
|
}
|
||||||
time.Sleep(time.Minute)
|
time.Sleep(time.Minute)
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
import {useCounterStore} from "@/stores/counter.ts";
|
import {useCounterStore} from "@/stores/counter.ts";
|
||||||
import {ref, watch} from 'vue'
|
import {ref, watch} from 'vue'
|
||||||
import axios from "@/axios.ts";
|
import axios from "@/axios.ts";
|
||||||
import {useRoute} from "vue-router"
|
|
||||||
|
|
||||||
|
|
||||||
// 创建响应式引用,用于存储API请求结果
|
// 创建响应式引用,用于存储API请求结果
|
||||||
@@ -19,6 +18,10 @@ const options = ref([] as string[])
|
|||||||
const deleteSpecifyDataVisible = ref(false)
|
const deleteSpecifyDataVisible = ref(false)
|
||||||
const inputSpecifyData = ref('')
|
const inputSpecifyData = ref('')
|
||||||
|
|
||||||
|
const deleteSpecifyDedupVisible = ref(false)
|
||||||
|
const inputSpecifyDedup = ref('')
|
||||||
|
const deleteSpecifyRawVisible = ref(false)
|
||||||
|
const inputSpecifyRaw = ref('')
|
||||||
|
|
||||||
const getInfo = () => {
|
const getInfo = () => {
|
||||||
if (value.value != '') {
|
if (value.value != '') {
|
||||||
@@ -60,6 +63,7 @@ getInfo()
|
|||||||
setInterval(getInfo, 5000)
|
setInterval(getInfo, 5000)
|
||||||
|
|
||||||
watch(value, (newValue) => {
|
watch(value, (newValue) => {
|
||||||
|
useCounterStore().token = value.value
|
||||||
getInfo()
|
getInfo()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -76,13 +80,35 @@ const deleteSpecifyData = () => {
|
|||||||
axios.delete('/api/token/info', {
|
axios.delete('/api/token/info', {
|
||||||
params: {
|
params: {
|
||||||
token: value.value,
|
token: value.value,
|
||||||
cache_list: inputSpecifyData.value,
|
both_number: inputSpecifyData.value,
|
||||||
}
|
}
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
getInfo()
|
getInfo()
|
||||||
deleteSpecifyDataVisible.value = false
|
deleteSpecifyDataVisible.value = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const deleteSpecifyDedup = () => {
|
||||||
|
axios.delete('/api/token/info', {
|
||||||
|
params: {
|
||||||
|
token: value.value,
|
||||||
|
dedup_bf: inputSpecifyDedup.value,
|
||||||
|
}
|
||||||
|
}).then(res => {
|
||||||
|
getInfo()
|
||||||
|
deleteSpecifyDedupVisible.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const deleteSpecifyRaw = () => {
|
||||||
|
axios.delete('/api/token/info', {
|
||||||
|
params: {
|
||||||
|
token: value.value,
|
||||||
|
cache_list: inputSpecifyRaw.value,
|
||||||
|
}
|
||||||
|
}).then(res => {
|
||||||
|
getInfo()
|
||||||
|
deleteSpecifyRawVisible.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
@@ -128,6 +154,10 @@ const deleteSpecifyData = () => {
|
|||||||
<p><b>管理</b></p>
|
<p><b>管理</b></p>
|
||||||
<el-button type="danger" @click="deleteDedup">删除全部去重参考值</el-button>
|
<el-button type="danger" @click="deleteDedup">删除全部去重参考值</el-button>
|
||||||
<el-button type="danger" @click="deleteRedis">删除全部原始数据</el-button>
|
<el-button type="danger" @click="deleteRedis">删除全部原始数据</el-button>
|
||||||
|
<div style="margin-top: 10px">
|
||||||
|
<el-button type="danger" @click="deleteSpecifyDedupVisible=true">删除指定数量去重参考值</el-button>
|
||||||
|
<el-button type="danger" @click="deleteSpecifyRawVisible=true">删除指定数量原始数据</el-button>
|
||||||
|
</div>
|
||||||
<div style="margin-top: 10px">
|
<div style="margin-top: 10px">
|
||||||
<el-button type="danger" @click="deleteSpecifyDataVisible=true">
|
<el-button type="danger" @click="deleteSpecifyDataVisible=true">
|
||||||
删除指定数量的数据(去重参考值+原始数据)
|
删除指定数量的数据(去重参考值+原始数据)
|
||||||
@@ -136,6 +166,22 @@ const deleteSpecifyData = () => {
|
|||||||
|
|
||||||
|
|
||||||
<!--弹窗输入-->
|
<!--弹窗输入-->
|
||||||
|
<el-dialog v-model="deleteSpecifyDedupVisible" title="删除指定数量去重参考值" width="400">
|
||||||
|
<el-input v-model="inputSpecifyDedup" style="width: 200px" placeholder="请输入删除数量"/>
|
||||||
|
<template #footer>
|
||||||
|
<el-button type="primary" @click="deleteSpecifyDedup">
|
||||||
|
确定
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
<el-dialog v-model="deleteSpecifyRawVisible" title="删除指定数量原始数据" width="400">
|
||||||
|
<el-input v-model="inputSpecifyRaw" style="width: 200px" placeholder="请输入删除数量"/>
|
||||||
|
<template #footer>
|
||||||
|
<el-button type="primary" @click="deleteSpecifyRaw">
|
||||||
|
确定
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
<el-dialog v-model="deleteSpecifyDataVisible" title="删除指定数量的数据" width="400">
|
<el-dialog v-model="deleteSpecifyDataVisible" title="删除指定数量的数据" width="400">
|
||||||
<el-input v-model="inputSpecifyData" style="width: 200px" placeholder="请输入删除数量"/>
|
<el-input v-model="inputSpecifyData" style="width: 200px" placeholder="请输入删除数量"/>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
|
@@ -39,6 +39,8 @@ const dataFormatOptions = [
|
|||||||
value: 'uid----secid----pid----comment_id',
|
value: 'uid----secid----pid----comment_id',
|
||||||
}, {
|
}, {
|
||||||
value: 'uid----secid',
|
value: 'uid----secid',
|
||||||
|
}, {
|
||||||
|
value: 'dyid',
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user