-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.go
919 lines (730 loc) · 19.3 KB
/
scan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
package reader
import (
"github.com/garyburd/redigo/redis"
"github.com/msinev/replicator/pool"
"github.com/msinev/replicator/protobuf/sendrecv"
"strconv"
"strings"
"sync"
// "github.com/go-kit/kit/util/conn"
"time"
)
/* -- DEBUG
func mainSave() {
var wg1 sync.WaitGroup
wg1.Add(1)
var consumeReplica=make(chan RedisKV, 100)
go pool.RedisExecutor();
dbnum, _:=strconv.Atoi(pool.GetEnvDefault("DB", "0"))
go kvConsumerSender(dbnum, consumeReplica, &wg1)
scan(dbnum, consumeReplica, nil);
wg1.Wait()
r:=DeltaReceiver{queue:nil, keyMap:nil}
r.Init()
r.Add("1", "77")
r.Add("2", "88")
r.Add("4", "88498")
r.Add("5", "8876")
r.Add("6", "8876")
json, err := r.queue.ToJSON()
if err != nil {
fmt.Println(err)
}
fmt.Println("Dump r.queue: \n", string(json), "\n")
DEBUG -- */
/* --
for r.Consume(buf, 2)>0 {
stdoutDumper := hex.Dumper(os.Stdout)
defer stdoutDumper.Close()
stdoutDumper.Write(buf.Bytes())
fmt.Println("\n==")
buf = new(bytes.Buffer)
}
-- */
/*
QOSIdle=make(chan TheMessage)
QOSLo=make(chan TheMessage)
QOSHi=make(chan TheMessage)
QOSRT=make(chan TheMessage)
OutBound=make(chan TheMessage)
go QOSScheduler()
*/
/* --
rw := bytes.NewBuffer(nil)
wu:=[]byte("Hello world!Hello world!Hello world!Hello world!Hello world!Hello worl"+
"Hello world!Hello world!Hello world!Hello world!Hello world!Hello "+
"Hello world!Hello world!Hello world!Hello world!Hello world!Hello "+"Hello world!Hello world!sHello world!Hello world!Hello dworld!Hello "+"Hello world!Hello world!Hello world!Hello world!Hello world!Hello "+"Hello world!Hello world!Hello world!Hello world!Hello world!Hello "+"Hello world!Hello world!Hello world!Hello world!Hello world!Hello ")
w := lz4.NewWriter(rw)
w.Write( wu )
w.Close()
outma,_:=lzma.Compress(wu)
fmt.Println(rw.Len())
fmt.Println(len(outma))
fmt.Println(len(wu))
}
-- */
type VersionData struct {
Version uint64
DeltaFor uint64
VersionData []RedisKV
}
func KVVersionGenerator(so ServerOptions, inc <-chan []RedisKV, outc chan<- VersionData) {
defer log.Infof("KVScanAccumulator %d terminated", so.DB)
defer close(outc)
//outc := client.kvPartSink[db] -- remove channels from client's structure after debugging
//inc :=client.kvFullScan[db] -- remove channels from client's structure after debugging
//kvbuf:=make([]RedisKV, 0, 20000)
ver := time.Now().Unix() * 10000
for kva := range inc {
//var err error
log.Noticef("DB %d KVVersionGenerator received %d Version %d ", so.DB, len(kva), ver)
ver++
outc <- VersionData{
Version: uint64(ver),
DeltaFor: uint64(ver - 1),
VersionData: kva,
}
}
}
/*
func reader(conn redis.Conn) {
var (
cursor int64
items []string
)
cursor=0
results := make([]string, 0)
for {
values, err := redis.Values( conn.Do("SSCAN", cursor) )
if err != nil {
return
}
values, err = redis.Scan(values, &cursor, &items)
if err != nil {
return
}
results = append(results, items...)
if cursor == 0 {
break
}
}
}
*/
type RedisKV = *sendrecv.Msg_SendValues
type RetriveOperation func(string, redis.Conn) error
type ReadOperation func(int64, string, redis.Conn) (error, RedisKV)
type TypeConverter struct {
init RetriveOperation
read ReadOperation
tag string
}
const maxrange = 1000000
func uselessTTL(ttl int64) bool {
return ttl == -2 || ttl >= 0 && ttl < 100
}
const versionKey = "version"
const versionKeyList = "version:"
func ReadVersionDelta(so ServerOptions, start <-chan string, out chan<- VersionData, initVersion uint64) { //Delta reader
db := so.DB
/*
if(nextVersion==nowVersion) {
select {
case out <- VersionData {
Version: nowVersion,
DeltaFor: fromVersion,
VersionData: existingKeys,
}: {
existingKeyIndexes = make(map[string]int)
existingKeys = make([] RedisKV, 200)
fromVersion=nowVersion
}
case nextVersion = <-start:
}
// return true, nowVersion, nil
}
*/
fromVersion := initVersion
checkStart := false
for {
log.Debugf("DB %d started delta loop version %d", db, fromVersion)
if !checkStart {
sT := <-start
log.Debugf("!! DB %d started delta after receiving mark %s ", db, sT)
} else {
log.Debugf("!! DB %d started delta repeat", db)
}
checkStart = false
chdone := make(chan uint64)
//
// --- exec begin --
//
pool.ExecutorGo <- func(conn redis.Conn) error {
nowVersion := fromVersion
//initVersion
defer close(chdone)
log.Noticef("Retrive version starting from %d", nowVersion)
defer log.Noticef("Retrive version complete %d to %d", fromVersion, nowVersion)
_, err := conn.Do("SELECT", db)
if err != nil {
return err
}
addVersionKeys := !so.Global.LocalVersion
nextVersion, err := redis.Uint64(conn.Do("GET", versionKey))
log.Noticef("Current next version %d", nextVersion)
if nowVersion < nextVersion {
newKeys := make(map[string]uint64)
existingKeyIndexes := make(map[string]int)
existingKeys := make([]RedisKV, 0)
for nowVersion < nextVersion {
//existingKeysCount:=len(existingKeyIndexes)
if addVersionKeys {
newKeys[versionKey] = nextVersion
}
versionListTTL, err := redis.Int(conn.Do("TTL", versionKeyList+strconv.FormatUint(fromVersion, 10)))
if err != nil {
return err
}
if versionListTTL == -2 {
return nil
}
for i := nowVersion + 1; i <= nextVersion; i++ {
lrKey := versionKeyList + strconv.FormatUint(i, 10)
if addVersionKeys {
newKeys[lrKey] = i
}
err := conn.Send("LRANGE", lrKey, 0, 10000)
log.Debugf("Send get keys for version %d", i)
if err != nil {
return err
}
}
conn.Flush()
for i := nowVersion + 1; i <= nextVersion; i++ {
rk, err := redis.Strings(conn.Receive())
if err != nil {
return err
} else {
for _, vv := range rk {
newKeys[vv] = i
}
log.Debugf("Got %d keys reply totaling %d pairs for version %d", len(rk), len(newKeys), i)
}
}
addKeys := make([]string, len(newKeys))
for key, _ := range newKeys {
addKeys = append(addKeys, key)
}
existingKeyIndexes, existingKeys, err = retriveKeys(existingKeyIndexes, existingKeys, addKeys, conn)
if err != nil {
return err
}
nextVersionCheck, err := redis.Uint64(conn.Do("GET", versionKey)) // check that no changes during retriving
if err != nil {
return err
}
if nextVersionCheck == nextVersion {
break
}
//
log.Infof("Version %d => %d changed while getting data to %d", nowVersion, nextVersion, nextVersionCheck)
nowVersion = nextVersion
nextVersion = nextVersionCheck
} // for
out <- VersionData{DeltaFor: fromVersion, Version: nextVersion, VersionData: existingKeys}
log.Infof("Sent version update %d -> %d %d pairs", fromVersion, nextVersion, len(existingKeys))
} else {
log.Infof("No changes in version %d", nextVersion)
}
chdone <- nextVersion
return nil
} // function
//
// --- exec end --
//
doLoop := true
for doLoop {
ok := false
select {
case sT := <-start:
checkStart = true
log.Debugf("DB %d receive mark %s", db, sT)
break
case fromVersion, ok = <-chdone:
if ok {
log.Debugf("Shifting db %d current version to %d", db, fromVersion)
} else {
log.Debugf("Delta db %d failed", db)
}
doLoop = false
}
} // Wait completed
} // for
}
func retriveKeys(existingKeyIndexes map[string]int, existingKeys []RedisKV, keys []string,
conn redis.Conn) (map[string]int, []RedisKV, error) {
lkeys := len(keys)
pttl := make([]int64, lkeys)
var err error
for _, val := range keys {
// log.Println("Sending info " + val)
err := conn.Send("PTTL", val)
if err != nil {
log.Error(err)
return existingKeyIndexes, existingKeys, err
}
}
conn.Flush()
for key, val := range keys {
// log.Println("Sending info " + val)
pttl[key], err = redis.Int64(conn.Receive())
if err != nil {
log.Error(err)
return existingKeyIndexes, existingKeys, err
}
if !uselessTTL(pttl[key]) {
err := conn.Send("TYPE", val)
if err != nil {
return existingKeyIndexes, existingKeys, err
}
}
}
conn.Flush()
cnv := make([]*TypeConverter, len(keys))
for keysKey, keysVal := range keys {
if !uselessTTL(pttl[keysKey]) {
keyType, err := redis.String(conn.Receive())
if err != nil {
return existingKeyIndexes, existingKeys, err
}
// log.Println("Received type " + keyType + " for "+ keysVal)
if err != nil {
return existingKeyIndexes, existingKeys, err
}
cnv[keysKey] = retriveFunctions[keyType]
cnv[keysKey].init(keysVal, conn)
}
}
conn.Flush()
lnewX := len(existingKeys)
for key, val := range keys {
ttk := pttl[key]
if !uselessTTL(ttk) {
err, data := cnv[key].read(ttk, val, conn)
if err != nil {
return existingKeyIndexes, existingKeys, err
}
ind, ok := existingKeyIndexes[val]
if ok {
existingKeys[ind] = data
} else {
existingKeys = append(existingKeys, data)
existingKeyIndexes[val] = lnewX
lnewX++
}
}
}
return existingKeyIndexes, existingKeys, nil
}
func retrive(keys []string, conn redis.Conn) (error, []RedisKV) { // for KeyReader
log.Notice("Retrive starting")
defer log.Notice("Retrive complete")
pttl := make([]int64, len(keys))
var err error
for _, val := range keys {
// log.Println("Sending info " + val)
err := conn.Send("PTTL", val)
if err != nil {
log.Error(err)
return err, nil
}
}
conn.Flush()
for key, val := range keys {
// log.Println("Sending info " + val)
pttl[key], err = redis.Int64(conn.Receive())
if err != nil {
log.Error(err)
return err, nil
}
if !uselessTTL(pttl[key]) {
err := conn.Send("TYPE", val)
if err != nil {
return err, nil
}
}
}
conn.Flush()
cnv := make([]*TypeConverter, len(keys))
for keysKey, keysVal := range keys {
if !uselessTTL(pttl[keysKey]) {
keyType, err := redis.String(conn.Receive())
if err != nil {
return err, nil
}
// log.Println("Received type " + keyType + " for "+ keysVal)
if err != nil {
return err, nil
}
cnv[keysKey] = retriveFunctions[keyType]
cnv[keysKey].init(keysVal, conn)
}
}
conn.Flush()
databuf := make([]RedisKV, len(keys))
for key, val := range keys {
ttk := pttl[key]
if !uselessTTL(ttk) {
err, data := cnv[key].read(ttk, val, conn)
if err != nil {
return err, nil
}
databuf[key] = data
}
}
return nil, databuf
}
func GetVersion(db int) (uint64, bool) {
var s sync.WaitGroup
s.Add(1)
var version uint64
var ok bool
pool.ExecutorGo <- func(conn redis.Conn) error {
ok = false
defer s.Done()
_, err := conn.Do("SELECT", db)
if err != nil {
return err
}
version, err = redis.Uint64(conn.Do("GET", versionKey))
if err != nil {
return nil
}
ok = true
return nil
}
s.Wait()
return version, ok
}
func KeyReader(db int, inp <-chan []string, out chan<- []RedisKV) {
// go pollLoop(&wg1)
defer close(out)
defer log.Infof("Exiting KeyReader function in db %d. Closing channel", db)
//}
log.Infof("Starting keyReader function in db %d", db)
for sa := range inp {
var s sync.WaitGroup
s.Add(1)
pool.ExecutorGo <- func(conn redis.Conn) error {
defer s.Done()
_, err := conn.Do("SELECT", db)
if err != nil {
return err
}
err, data := retrive(sa, conn)
if err != nil {
log.Error(err)
return err
}
out <- data
return nil
}
s.Wait()
}
}
func ScanVersion(so ServerOptions, version uint64, out chan<- VersionData) {
var wg sync.WaitGroup
db := so.DB
wg.Add(1)
fallback := true
fromVersion := version
pool.ExecutorGo <- func(conn redis.Conn) error {
defer wg.Done()
nowVersion := fromVersion
//initVersion
//defer close(chdone)
log.Noticef("Retrive version starting from %d", nowVersion)
defer log.Noticef("Retrive version complete %d to %d", fromVersion, nowVersion)
_, err := conn.Do("SELECT", db)
if err != nil {
return err
}
addVersionKeys := !so.Global.LocalVersion
nextVersion, err := redis.Uint64(conn.Do("GET", versionKey))
log.Noticef("Current next version %d", nextVersion)
if nowVersion < nextVersion {
//nextVersion, err := redis.Uint64(conn.Do("EXISTS", versionKey))
newKeys := make(map[string]uint64)
existingKeyIndexes := make(map[string]int)
existingKeys := make([]RedisKV, 0)
for nowVersion < nextVersion {
//existingKeysCount:=len(existingKeyIndexes)
if addVersionKeys {
newKeys[versionKey] = nextVersion
}
vlKey := versionKeyList + strconv.FormatUint(fromVersion, 10)
versionListTTL, err := redis.Int(conn.Do("TTL", vlKey))
if err != nil {
return err
}
if versionListTTL < 0 {
log.Errorf("Invalid %s TTL %d, doing fallback", vlKey, versionListTTL)
return nil
}
for i := nowVersion + 1; i <= nextVersion; i++ {
lrKey := versionKeyList + strconv.FormatUint(i, 10)
if addVersionKeys {
newKeys[lrKey] = i
}
err := conn.Send("LRANGE", lrKey, 0, 10000)
log.Debugf("Send get keys for version %d", i)
if err != nil {
return err
}
}
conn.Flush()
fail := uint64(0)
for i := nowVersion + 1; i <= nextVersion; i++ {
rk, err := redis.Strings(conn.Receive())
if err != nil {
return err
} else if len(rk) == 0 {
fail = i
break
} else {
for _, vv := range rk {
newKeys[vv] = i
}
log.Debugf("Got %d keys reply totaling %d pairs for version %d", len(rk), len(newKeys), i)
}
}
if fail != 0 {
log.Errorf("Missing version %d list, doing fallback", fail)
return nil
}
addKeys := make([]string, len(newKeys))
for key, _ := range newKeys {
addKeys = append(addKeys, key)
}
existingKeyIndexes, existingKeys, err = retriveKeys(existingKeyIndexes, existingKeys, addKeys, conn)
if err != nil {
return err
}
nextVersionCheck, err := redis.Uint64(conn.Do("GET", versionKey)) // check that no changes during retriving
if err != nil {
return err
}
if nextVersionCheck == nextVersion {
break
}
//
log.Infof("Version %d => %d changed while getting data to %d", nowVersion, nextVersion, nextVersionCheck)
nowVersion = nextVersion
nextVersion = nextVersionCheck
} // for
out <- VersionData{DeltaFor: fromVersion, Version: nextVersion, VersionData: existingKeys}
log.Infof("Sent version update %d -> %d %d pairs", fromVersion, nextVersion, len(existingKeys))
fallback = false
} else if nowVersion == nextVersion {
out <- VersionData{DeltaFor: fromVersion, Version: nextVersion, VersionData: make([]RedisKV, 0)}
fallback = false
log.Infof("No changes in version %d", nextVersion)
}
// chdone <- nextVersion
return nil
} // function
//
// --- exec end --
//
wg.Wait()
if fallback {
Scan(so, out)
}
}
func Scan(so ServerOptions, out chan<- VersionData) {
db := so.DB
log.Infof("Starting scan function on db %d", db)
//out:=<-call
// TODO: In case of REDIS preformance bottleneck make a batch reading to send same scan to all of them
pool.ExecutorGo <- func(conn redis.Conn) error {
defer close(out)
defer log.Infof("Exiting scan function in db %d. Closing channel", db)
//}
_, err := conn.Do("SELECT", db)
if err != nil {
return err
}
ver, err := redis.Int64(conn.Do("GET", versionKey))
if err != nil {
log.Criticalf("Unable to get root %s key in db %d. Aborting scan", versionKey, db)
return nil
}
iter := 0
var data []RedisKV
filterPrefix := versionKey
flp := len(filterPrefix)
for {
//log.Printf("Sending scan %d \n" , iter)
arr, err := redis.MultiBulk(conn.Do("SCAN", iter))
if err != nil {
log.Error(err)
return err
} else {
// now we get the iter and the keys from the multi-bulk reply
olditer := iter
iter, _ = redis.Int(arr[0], nil)
keys, _ := redis.Strings(arr[1], nil)
lkeys := len(keys)
log.Debugf("SCAN DB %d ITER %d -> %d KEYS %d", db, olditer, iter, lkeys)
rkeys := keys
if so.Global.LocalVersion {
rkeys = make([]string, 0, lkeys)
for _, v := range keys {
if !(strings.HasPrefix(v, filterPrefix) && (len(v) == flp || v[flp] == ':')) {
rkeys = append(rkeys, v)
}
}
log.Warningf("DB %s scan filered version keys %d -> %d", db, lkeys, len(rkeys))
}
err, nextdata := retrive(rkeys, conn)
data = append(data, nextdata...)
if err != nil {
log.Error(err)
return err
}
defer log.Infof("Sent scan result on db %d. Version %d with %d keys", db, ver, len(data))
// scan(iter)
}
if iter == 0 {
out <- VersionData{
Version: uint64(ver),
DeltaFor: 0,
VersionData: data,
}
return nil
}
}
}
}
func writeSV(conn redis.Conn, vv *sendrecv.Msg_SendValues, reset bool) (int, error) {
Reply := 0
ttls := int(vv.GetTTL()/1000) + 1
switch vv.Value.(type) {
case *sendrecv.Msg_SendValues_Strvalue:
//log.Printf("SET %s -> %s", vv.GetKey(), vv.GetStrvalue())
if vv.TTL != nil {
err := conn.Send("SETEX", vv.GetKey(), ttls, vv.GetStrvalue())
return 1, err
} else {
err := conn.Send("SET", vv.GetKey(), vv.GetStrvalue())
return 1, err
}
case *sendrecv.Msg_SendValues_Listvalue:
list := vv.GetListvalue()
//log.Printf("SETLIST %s -> %d", vv.GetKey(), len(list.Value))
if !reset {
err := conn.Send("DEL", vv.GetKey())
if err != nil {
return Reply, err
}
Reply++
}
for _, lv := range list.Value {
err := conn.Send("RPUSH", vv.GetKey(), lv)
if err != nil {
return Reply, err
}
Reply++
}
if vv.TTL != nil {
err := conn.Send("EXPIRE", vv.GetKey(), ttls)
if err != nil {
return Reply, err
}
Reply++
}
return Reply, nil
}
return Reply, nil
}
/*
func mainRead() {
var wg1 sync.WaitGroup
wg1.Add(1)
//var consumeReplica=make(chan RedisKV, 100)
go pool.RedisExecutor()
dbnum, _:=strconv.Atoi(pool.GetEnvDefault("DB", "5"))
dbout, _:=strconv.Atoi(pool.GetEnvDefault("DBOUT", "7"))
msg := loadMsg(dbnum)
writeKeys(dbout,msg,&wg1)
// go kvConsumerSender(dbnum, consumeReplica, &wg1)
// scan(dbnum, consumeReplica, nil);
wg1.Wait()
}
func mainLoad() {
log.SetFlags(log.Lshortfile)
cer, err := tls.LoadX509KeyPair("server.crt", "server.key")
if err != nil {
log.Println(err)
return
}
config := &tls.Config{Certificates: []tls.Certificate{cer}}
ln, err := tls.Listen("tcp", ":443", config)
if err != nil {
log.Println(err)
return
}
defer ln.Close()
for {
conn, err := ln.Accept()
if err != nil {
log.Println(err)
continue
}
go handleConnection(conn)
}
}
func handleConnection(conn net.Conn) {
defer conn.Close()
r := bufio.NewReader(conn)
for {
msg, err := r.ReadString('\n')
if err != nil {
log.Println(err)
return
}
println(msg)
n, err := conn.Write([]byte("world\n"))
if err != nil {
log.Println(n, err)
return
}
}
}
*/
// https://github.com/fatih/pool/blob/v2.0.0/channel.go
// Factory is a function to create new connections.
/*
const RedisExchangeKey="mapping"
var ExecuteLoadRequest chan bool
func InitRedisScan() {
var (
cursor int64
items []string
)
results := make([]string, 0)
for {
values, err := redis.Values(conn.Do("SSCAN", key, cursor))
if err != nil {
return
}
values, err = redis.Scan(values, &cursor, &items)
if err != nil {
return
}
results = append(results, items)
if cursor == 0 {
break
}
}
}
*/