@@ -37,10 +37,11 @@ import (
3737)
3838
3939const (
40- RedisStructureString = "1"
41- RedisStructureHash = "2"
42- RedisStructureList = "3"
43- RedisStructureSet = "4"
40+ RedisStructureString = "String"
41+ RedisStructureHash = "Hash"
42+ RedisStructureList = "List"
43+ RedisStructureSet = "Set"
44+ RedisStructureSortedSet = "SortedSet"
4445
4546 ValEncoderJson = "json"
4647 ValEncoderKVCommas = "kv-commas"
@@ -93,12 +94,14 @@ type Rule struct {
9394 RedisHashFieldPrefix string `yaml:"redis_hash_field_prefix"`
9495 // 使用哪个列的值作为hash的field,仅redis_structure为hash时起作用
9596 RedisHashFieldColumn string `yaml:"redis_hash_field_column"`
96-
97- RedisKeyColumnIndex int
98- RedisKeyColumnIndexs []int
99- RedisKeyColumnIndexMap map [string ]int
100- RedisHashFieldColumnIndex int
101- RedisHashFieldColumnIndexs []int
97+ // Sorted Set(有序集合)的Score
98+ RedisSortedSetScoreColumn string `yaml:"redis_sorted_set_score_column"`
99+ RedisKeyColumnIndex int
100+ RedisKeyColumnIndexs []int
101+ RedisKeyColumnIndexMap map [string ]int
102+ RedisHashFieldColumnIndex int
103+ RedisHashFieldColumnIndexs []int
104+ RedisSortedSetScoreColumnIndex int
102105
103106 // ------------------- ROCKETMQ -----------------
104107 RocketmqTopic string `yaml:"rocketmq_topic"` //rocketmq topic名称,可以为空,为空时使用表名称
@@ -191,21 +194,6 @@ func RuleInsList() []*Rule {
191194 return list
192195}
193196
194- func StructureName (structure string ) string {
195- switch structure {
196- case RedisStructureString :
197- return "string"
198- case RedisStructureHash :
199- return "hash"
200- case RedisStructureList :
201- return "list"
202- case RedisStructureSet :
203- return "set"
204- }
205-
206- return ""
207- }
208-
209197func (s * Rule ) Initialize () error {
210198 if err := s .buildPaddingMap (); err != nil {
211199 return err
@@ -513,8 +501,21 @@ func (s *Rule) initRedisConfig() error {
513501 if s .RedisKeyValue == "" {
514502 return errors .New ("empty redis_key_value not allowed in rule" )
515503 }
504+ case "SORTEDSET" :
505+ s .RedisStructure = RedisStructureSortedSet
506+ if s .RedisKeyValue == "" {
507+ return errors .New ("empty redis_key_value not allowed in rule" )
508+ }
509+ if s .RedisSortedSetScoreColumn == "" {
510+ return errors .New ("empty redis_sorted_set_score_column not allowed in rule" )
511+ }
512+ _ , index := s .TableColumn (s .RedisSortedSetScoreColumn )
513+ if index < 0 {
514+ return errors .New ("redis_sorted_set_score_column must be table column" )
515+ }
516+ s .RedisHashFieldColumnIndex = index
516517 default :
517- return errors .Errorf (" redis_structure must be string or hash or list or set" )
518+ return errors .Errorf ("redis_structure must be string or hash or list or set" )
518519 }
519520
520521 if s .RedisKeyColumn != "" {
@@ -664,9 +665,11 @@ func (s *Rule) PreCompileLuaScript(dataDir string) error {
664665 strings .Contains (script , `HSET(` ) ||
665666 strings .Contains (script , `RPUSH(` ) ||
666667 strings .Contains (script , `SADD(` ) ||
668+ strings .Contains (script , `ZADD(` ) ||
667669 strings .Contains (script , `DEL(` ) ||
668670 strings .Contains (script , `HDEL(` ) ||
669671 strings .Contains (script , `LREM(` ) ||
672+ strings .Contains (script , `ZREM(` ) ||
670673 strings .Contains (script , `SREM(` )) {
671674
672675 return errors .New ("lua script incorrect format" )
0 commit comments