Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.7.x redis 插件 #139

Open
wants to merge 6 commits into
base: v1.7.x
Choose a base branch
from
Open

V1.7.x redis 插件 #139

wants to merge 6 commits into from

Conversation

Ryan-gsq
Copy link

说明文档:

Type

key=>value : SET 命令写入数据

List : LPUSH 命令写入数据

Hash : HSET 命令写入数据

Zset : ZSET 命令写入数据

SET : SADD 命令写入数据

DataType

custom : 指定写入哪些数据, 选择这个,通过 Value 参数编辑数据

auto json : 自动将选择中的Fields 进行json 写入Redis

Key

Redis 写入数据时候的key值,{$SchemaName},{$TableName},{$EventType},{$"+filedName+"} 标签将会替换成数据库名 ,表名 ,事件类型 , 甚至字段内容

HashKey

Redis 写入Hash数据时候的key值,{$SchemaName},{$TableName},{$EventType},{$"+filedName+"} 标签将会替换成数据库名 ,表名 ,事件类型 , 甚至字段内容

Sort

Redis 写入Sorted set 数据时候的sort值 标签会自动替换为 {$"+filedName+"} 字段内容, *****请确保改字段是数字类型*****, 如果不是将自动使用 0

Custom Value

自定义写入Redis 的内容当DataType == Custom 的时候 , 同样会标签替换 替换规则: {$SchemaName},{$TableName},{$EventType},{$"+filedName+"}

Expired

key=>value 消息过期时间,单位秒. *****注意: 仅 key=>value 支持*****,必须为 int 类型,默认为0,不过期, CRUD 会同步到redis 上, 该参数一般不需要设置

doc

全部类型 测试 写入json

数据类型
数据类型2
写入结果

Zset 类型 测试 写入 自定义内容

自定义内容 zset 配置
自定义内容 zset

@jc3wish
Copy link
Member

jc3wish commented Mar 20, 2021

1 . Type : list 的时候,Del 事件的时候,数据被 lrem 删除了,list 旧版本中,数据是不会被 删除的,不管什么逻辑,都是 lpush 的方式写入

  1. key=>val, hash, zset, list ,sadd 都有多途 del 的逻辑

在 insert ,update 指令的时候,写新数据进去,不是会被复盖吗? 需要自行操作一次 del ?
假如 key 由于变值的 变更导致,可否 进行一次 key != oldkey 判断 一次?减少一次 redis io 请求

//删除之前的内容 if len(data.Rows) >= 2 { oldKey := This.getTemplateVal(data, This.p.KeyConfig, 0) pipeline.Del(ctx, oldKey) } pipeline.Set(ctx, key, content, time.Duration(This.p.Expired)*time.Second)

  1. DataType : json 的时候,zset, sadd 等操作,在 del 的时候,是删除不了的,因为这个操作 redis 需要根据内容值 对比,但是 map => json 字符串的时候,key 是无序的,所以前后两次 值 是对不上的,这个应该界面提示用户,只限 custom 自定义的时候有效

  2. 界面 input 默认值

keyConfig : {$SchemaName}-{$TableName}-{$}

等是否会更好一点?

  1. 提示内容

(ps: filedName 替换为字段名 字段必须勾选才能替换)

加上,不选字段的情况下,默认全选

5 缺少单元测试

参考进行修改

`
package src_test

import (
MyPlugin "github.com/brokercap/Bifrost/plugin/redis/src"
"testing"
)

func getParamByType(Type string,DataType string) map[string]interface{}{
p := make(map[string]interface{},0)
switch DataType {
case "json","string":
break
case "custom":
p["ValConfig"] = "{$SchemaName}-{$TableName}-{$id}"
break
default:
DataType = "json"
break
}

p["DataType"] = DataType
switch Type {
case "set":
	p["KeyConfig"] = "{$SchemaName}-{$TableName}-{$id}"
	p["Type"] = "set"
case "list":
	p["KeyConfig"] = "{$SchemaName}-{$TableName}-list"
	p["Type"] = "list"
case "hash":
	p["KeyConfig"] = "{$SchemaName}-{$TableName}-hash"
	p["Type"] = "hash"
	p["HashKey"] = "{$id}"
case "sadd":
	p["KeyConfig"] = "{$SchemaName}-{$TableName}-sadd"
	p["Type"] = "sadd"
case "zset":
	p["KeyConfig"] = "{$SchemaName}-{$TableName}-zset"
	p["Type"] = "zset"
default:
	p["KeyConfig"] = "{$SchemaName}-{$TableName}-{$id}"
	p["Type"] = "set"
}
p["Sort"] = "{$id}"
p["Expired"] = 10
return p

}

var TypeArr = []string{"list","set","hash","sadd","zset"}

func InsertDataFun(Type string,DataType string) error {
testBefore()
myConn := MyPlugin.NewConn()
myConn.SetOption(&url,nil)
myConn.Open()
myConn.SetParam(getParamByType(Type,DataType))
,,err := myConn.Insert(event.GetTestInsertData(),false)
myConn.Close()
return err
}

func UpdateDataFun(Type string,DataType string) error {
testBefore()
myConn := MyPlugin.NewConn()
myConn.SetOption(&url,nil)
myConn.Open()
myConn.SetParam(getParamByType(Type,DataType))
,,err := myConn.Update(event.GetTestUpdateData(),false)
myConn.Close()
return err
}

func DelDataFun(Type string,DataType string) error {
testBefore()
myConn := MyPlugin.NewConn()
myConn.SetOption(&url,nil)
myConn.Open()
myConn.SetParam(getParamByType(Type,DataType))
,,err := myConn.Del(event.GetTestDeleteData(),false)
myConn.Close()
return err
}

// 执行完,去 redis 查看 key 数据对否
func TestInsertByAllTypeAndJson(t *testing.T){
var isAllSuccess bool = true
for _, Type := range TypeArr {
err := InsertDataFun(Type,"json")
if err != nil {
t.Errorf("Type:%s Err:%s",Type,err.Error())
isAllSuccess = false
}
}
if isAllSuccess {
t.Log("success")
}
}

// 执行完,去 redis 查看 key 数据对否
func TestUpdateByAllTypeAndJson(t *testing.T){
var isAllSuccess bool = true
for _, Type := range TypeArr {
err := UpdateDataFun(Type,"json")
if err != nil {
t.Errorf("Type:%s Err:%s",Type,err.Error())
isAllSuccess = false
}
}
if isAllSuccess {
t.Log("success")
}
}

// 执行完,去 redis 查看 key 数据对否
func TestDelByAllTypeAndJson(t *testing.T){
var isAllSuccess bool = true
for _, Type := range TypeArr {
err := DelDataFun(Type,"json")
if err != nil {
t.Errorf("Type:%s Err:%s",Type,err.Error())
isAllSuccess = false
}
}
if isAllSuccess {
t.Log("success")
}
}

// 执行完,去 redis 查看 key 数据对否
func TestInsertByAllTypeAndCustom(t *testing.T){
var isAllSuccess bool = true
for _, Type := range TypeArr {
err := InsertDataFun(Type,"custom")
if err != nil {
t.Errorf("Type:%s Err:%s",Type,err.Error())
isAllSuccess = false
}
}
if isAllSuccess {
t.Log("success")
}
}

// 先执行 TestInsertByAllTypeAndCustom 再执TestDelByAllTypeAndCustom 行去 redis 查看 key 数据对否
func TestDelByAllTypeAndCustom(t *testing.T){
var isAllSuccess bool = true
for _, Type := range TypeArr {
err := DelDataFun(Type,"custom")
if err != nil {
t.Errorf("Type:%s Err:%s",Type,err.Error())
isAllSuccess = false
}
}
if isAllSuccess {
t.Log("success")
}
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants