7
7
"github.com/ByteStorage/FlyDB/engine"
8
8
_const "github.com/ByteStorage/FlyDB/lib/const"
9
9
"github.com/ByteStorage/FlyDB/lib/encoding"
10
+ "regexp"
10
11
"time"
11
12
)
12
13
@@ -229,6 +230,27 @@ func (s *SetStructure) SDiff(keys ...string) ([]string, error) {
229
230
return diffMembers , nil
230
231
}
231
232
233
+ // Keys returns all the keys of the set structure
234
+ func (s * SetStructure ) Keys (regx string ) ([]string , error ) {
235
+ toRegexp := convertToRegexp (regx )
236
+ compile , err := regexp .Compile (toRegexp )
237
+ if err != nil {
238
+ return nil , err
239
+ }
240
+ var keys []string
241
+ byteKeys := s .db .GetListKeys ()
242
+ for _ , key := range byteKeys {
243
+ if compile .MatchString (string (key )) {
244
+ // check if deleted
245
+ if ! s .exists (string (key )) {
246
+ continue
247
+ }
248
+ keys = append (keys , string (key ))
249
+ }
250
+ }
251
+ return keys , nil
252
+ }
253
+
232
254
// SUnionStore calculates and stores the union of multiple sets
233
255
// in a destination set.
234
256
//
@@ -385,7 +407,7 @@ type FSetWithTTL struct {
385
407
386
408
// setSetToDB
387
409
func (s * SetStructure ) setSetToDB (key []byte , zSetValue * FSets , ttl time.Duration ) error {
388
- // 创建新的结构体实例,包含zSetValue和TTL值
410
+ // create a new zSetValueWithTTL struct
389
411
var expire int64 = 0
390
412
391
413
if ttl != 0 {
@@ -398,7 +420,7 @@ func (s *SetStructure) setSetToDB(key []byte, zSetValue *FSets, ttl time.Duratio
398
420
}
399
421
400
422
val := encoding .NewMessagePackEncoder ()
401
- err := val .Encode (valueWithTTL ) // 编码包含zSetValue和TTL的新的结构体
423
+ err := val .Encode (valueWithTTL ) // Encode the value along with TTL
402
424
if err != nil {
403
425
return err
404
426
}
@@ -427,15 +449,6 @@ func (s *FSets) exists(member ...string) bool {
427
449
return true
428
450
}
429
451
430
- func (s * SetStructure ) Keys () ([]string , error ) {
431
- var keys []string
432
- byte_keys := s .db .GetListKeys ()
433
- for _ , key := range byte_keys {
434
- keys = append (keys , string (key ))
435
- }
436
- return keys , nil
437
- }
438
-
439
452
func (s * SetStructure ) Stop () error {
440
453
err := s .db .Close ()
441
454
return err
0 commit comments