-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
962 lines (767 loc) · 19.3 KB
/
context.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
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
package connctx
import (
"context"
"sync"
"time"
)
type Context interface {
context.Context
// Close 清理资源
Close()
// Del 删除key
Del(keys ...string) (delNum int)
// Get 获取key值
Get(key string) (value interface{}, exists bool)
// Set 设置key值
Set(key string, value interface{})
// SetNx 设置key的值,当且仅当key不存在
SetNx(key string, value interface{}) (ok bool)
// GetSet 设置key的值,并返回key的旧值
GetSet(key string, value interface{}) (old interface{})
// IncrBy 将key所储存的值加上增量value
// key存储的数据仅支持int和int64两种数据类型,否则返回类型错误
IncrBy(key string, value int64) (newValue int64, err error)
// DecrBy 将key所储存的值减去增量value
// key存储的数据仅支持int和int64两种数据类型,否则返回类型错误
DecrBy(key string, value int64) (newValue int64, err error)
// Incr 将key所储存的值加上1
// key存储的数据仅支持int和int64两种数据类型,否则返回类型错误
Incr(key string) (newValue int64, err error)
// Decr 将key所储存的值减去1
// key存储的数据仅支持int和int64两种数据类型,否则返回类型错误
Decr(key string) (newValue int64, err error)
// SetBit 对key所储存的[]byte,设置或清除指定偏移量上的位(bit)
// key存储的数据仅支持[]byte,否则返回类型错误
SetBit(key string, offset uint16, val bool) (oldValue bool, err error)
// GetBit 对key所储存的[]byte,获取指定偏移量上的位(bit)
// key存储的数据仅支持[]byte,否则返回类型错误
GetBit(key string, offset uint16) (value bool, err error)
// HasBit 对key所储存的[]byte,获取是否含有比特位为1的位
// key存储的数据仅支持[]byte,否则返回类型错误
HasBit(key string) (has bool, err error)
// BitCount 对key所储存的[]byte,获取被设置为1的比特位数量
// key存储的数据仅支持[]byte,否则返回类型错误
BitCount(key string) (num int, err error)
// LPush 将一个或多个值插入到列表key的表头
LPush(key string, items ...interface{}) (length int, err error)
// RPush 将一个或多个值插入到列表key的表尾
RPush(key string, items ...interface{}) (length int, err error)
// LPop 移除并返回列表key的头元素
LPop(key string) (value interface{}, err error)
// LIndex 返回列表key中,下标为index的元素
LIndex(key string, index int) (value interface{}, err error)
// LSet 将列表key下标为index的元素的值设置为value
LSet(key string, index int, value interface{}) (err error)
// LLen 返回列表key的长度
LLen(key string) (length int, err error)
// LRange 返回列表key中指定区间内的元素,区间以偏移量start和stop指定
// 参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推
LRange(key string, start, end int) (valueList []interface{}, err error)
// LTrim 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除
LTrim(key string, start, end int) (err error)
// LTrimLastest 对一个列表进行修剪(trim),保留列表key的表尾最近count条数据
LTrimLastest(key string, count int) (err error)
// SAdd 将一个或多个元素加入到集合key当中,已经存在于集合的元素将被忽略
// 注意:items中不同数据类型会被认为是不同的元素
SAdd(key string, items ...interface{}) (newNum int, err error)
// SCard 返回集合key中元素的数量
SCard(key string) (total int, err error)
// SMembers 返回集合key中的所有成员
SMembers(key string) (items []interface{}, err error)
// SIsMember 判断元素是否是集合key的成员
SIsMember(key string, item interface{}) (isMem bool, err error)
// SRem 移除集合key中的一个或多个元素,不存在的元素会被忽略
SRem(key string, items ...interface{}) (delNum int, err error)
// SPop 移除并返回集合中的一个随机元素
SPop(key string) (item interface{}, err error)
// SRandMember 返回集合中的一个随机元素
SRandMember(key string) (item interface{}, err error)
// HSet 将哈希表key中的域field的值设为value
HSet(key, field string, value interface{}) (isCreate bool, err error)
// HGet 返回哈希表key中给定域field的值
HGet(key, field string) (value interface{}, err error)
// HGetAll 返回哈希表key中,所有的域和值
HGetAll(key string) (value Hash, err error)
// HDel 删除哈希表key中的一个或多个指定域,不存在的域将被忽略
HDel(key string, fields ...string) (delNum int, err error)
// HIncrBy 为哈希表key中的域field的值加上增量value
// field中存储的数据仅支持int和int64两种数据类型,否则返回类型错误
HIncrBy(key string, field string, value int64) (newValue int64, err error)
// HLen 返回哈希表key中域的数量
HLen(key string) (length int, err error)
// HSetNx 将哈希表key中的域field的值设置为value,当且仅当域field不存在
HSetNx(key, field string, value interface{}) (ok bool, err error)
// HSAdd 将一个或多个元素加入到哈希表key中域field集合中,已经存在于集合的元素将被忽略
HSAdd(key, field string, items ...interface{}) (newNum int, err error)
// HSCard 返回哈希表key中域field集合中元素的数量
HSCard(key, field string) (total int, err error)
// HSMembers 返回哈希表key中域field集合中的所有成员
HSMembers(key, field string) (items []interface{}, err error)
// HSIsMember 判断元素是否是哈希表key中域field集合的成员
HSIsMember(key, field string, item interface{}) (isMem bool, err error)
// HSRem 移除哈希表key中域field中的一个或多个元素,不存在的元素会被忽略
HSRem(key, field string, items ...interface{}) (delNum int, err error)
// HSPop 移除并返回哈希表key中域field集合中的一个随机元素
HSPop(key, field string) (item interface{}, err error)
// HSRandMember 返回哈希表key中域field集合中的一个随机元素
HSRandMember(key, field string) (item interface{}, err error)
// HSetBit 对哈希表key中域field所储存的[]byte,设置或清除指定偏移量上的位(bit)
// field存储的数据仅支持[]byte,否则返回类型错误
HSetBit(key, field string, offset uint16, val bool) (oldValue bool, err error)
// HGetBit 对哈希表key中域field所储存的[]byte,获取指定偏移量上的位(bit)
// field存储的数据仅支持[]byte,否则返回类型错误
HGetBit(key, field string, offset uint16) (value bool, err error)
// HHasBit 对哈希表key中域field所储存的[]byte,获取是否含有比特位为1的位
// field存储的数据仅支持[]byte,否则返回类型错误
HHasBit(key, field string) (has bool, err error)
// HBitCount 对哈希表key中域field所储存的[]byte,获取被设置为1的比特位数量
// field存储的数据仅支持[]byte,否则返回类型错误
HBitCount(key, field string) (num int, err error)
}
type ctx struct {
mutex sync.RWMutex
data Hash
}
func newCtx() Context {
c := &ctx{}
return c
}
func (c *ctx) reset() {
c.data = nil
}
func (c *ctx) setOrUpdate(handler func()) {
c.mutex.Lock()
defer c.mutex.Unlock()
if c.data == nil {
c.data = Hash{}
}
handler()
}
func (c *ctx) Close() {
c.reset()
ctxPool.Put(c)
}
func (c *ctx) Del(keys ...string) (delNum int) {
c.mutex.Lock()
defer c.mutex.Unlock()
if len(c.data) < 1 {
return
}
return c.data.del(keys...)
}
func (c *ctx) Get(key string) (value interface{}, exists bool) {
c.mutex.RLock()
defer c.mutex.RUnlock()
return c.data.get(key)
}
func (c *ctx) Set(key string, value interface{}) {
c.setOrUpdate(func() {
c.data.set(key, value)
})
}
func (c *ctx) SetNx(key string, value interface{}) (ok bool) {
c.mutex.Lock()
defer c.mutex.Unlock()
return c.data.setnx(key, value)
}
func (c *ctx) GetSet(key string, value interface{}) (old interface{}) {
c.setOrUpdate(func() {
old = c.data.getSet(key, value)
})
return
}
func (c *ctx) IncrBy(key string, value int64) (newValue int64, err error) {
c.setOrUpdate(func() {
newValue, err = c.data.incrBy(key, value)
})
return
}
func (c *ctx) DecrBy(key string, value int64) (newValue int64, err error) {
return c.IncrBy(key, -value)
}
func (c *ctx) Incr(key string) (newValue int64, err error) {
return c.IncrBy(key, 1)
}
func (c *ctx) Decr(key string) (newValue int64, err error) {
return c.IncrBy(key, -1)
}
func (c *ctx) SetBit(key string, offset uint16, value bool) (oldValue bool, err error) {
c.setOrUpdate(func() {
oldValue, err = c.data.setBit(key, offset, value)
})
return
}
func (c *ctx) GetBit(key string, offset uint16) (value bool, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if c.data == nil {
return
}
return c.data.getBit(key, offset)
}
func (c *ctx) HasBit(key string) (has bool, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if c.data == nil {
return
}
return c.data.hasBit(key)
}
func (c *ctx) BitCount(key string) (num int, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if c.data == nil {
return
}
return c.data.bitCount(key)
}
func (c *ctx) LPush(key string, items ...interface{}) (length int, err error) {
if len(items) < 1 {
return
}
c.setOrUpdate(func() {
value, exists := c.data[key]
if !exists {
l := &list{}
l.prepend(items...)
length = l.length
c.data[key] = l
return
}
val, ok := value.(*list)
if !ok {
err = ErrType
return
}
val.prepend(items...)
length = val.length
})
return
}
func (c *ctx) RPush(key string, items ...interface{}) (length int, err error) {
if len(items) < 1 {
return
}
c.setOrUpdate(func() {
value, exists := c.data[key]
if !exists {
l := &list{}
l.append(items...)
length = l.length
c.data[key] = l
return
}
val, ok := value.(*list)
if !ok {
err = ErrType
return
}
val.append(items...)
length = val.length
})
return
}
func (c *ctx) LPop(key string) (value interface{}, err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if len(c.data) < 1 {
return
}
val, exists := c.data[key]
if !exists {
return
}
v, ok := val.(*list)
if !ok {
err = ErrType
return
}
value = v.lpop()
return
}
func (c *ctx) LIndex(key string, index int) (value interface{}, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if len(c.data) < 1 {
return
}
val, exists := c.data[key]
if !exists {
return
}
v, ok := val.(*list)
if !ok {
err = ErrType
return
}
value = v.index(index)
return
}
func (c *ctx) LSet(key string, index int, value interface{}) (err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if len(c.data) < 1 {
return
}
val, exists := c.data[key]
if !exists {
return
}
v, ok := val.(*list)
if !ok {
err = ErrType
return
}
return v.set(index, value)
}
func (c *ctx) LLen(key string) (length int, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if len(c.data) < 1 {
return
}
val, exists := c.data[key]
if !exists {
return
}
v, ok := val.(*list)
if !ok {
err = ErrType
return
}
length = v.length
return
}
func (c *ctx) LRange(key string, start, end int) (valueList []interface{}, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if len(c.data) < 1 {
return
}
val, exists := c.data[key]
if !exists {
return
}
v, ok := val.(*list)
if !ok {
err = ErrType
return
}
return v.lrange(start, end)
}
func (c *ctx) LTrim(key string, start, end int) (err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if len(c.data) < 1 {
return
}
val, exists := c.data[key]
if !exists {
return
}
v, ok := val.(*list)
if !ok {
err = ErrType
return
}
v.trim(start, end)
return
}
func (c *ctx) LTrimLastest(key string, count int) (err error) {
return c.LTrim(key, -count, -1)
}
func (c *ctx) SAdd(key string, items ...interface{}) (newNum int, err error) {
c.setOrUpdate(func() {
newNum, err = c.data.sAdd(key, items...)
})
return
}
func (c *ctx) SCard(key string) (total int, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if c.data == nil {
return
}
return c.data.sCard(key)
}
func (c *ctx) SMembers(key string) (items []interface{}, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if c.data == nil {
return
}
return c.data.sMembers(key)
}
func (c *ctx) SIsMember(key string, item interface{}) (isMem bool, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if c.data == nil {
return
}
return c.data.sIsMember(key, item)
}
func (c *ctx) SRem(key string, items ...interface{}) (delNum int, err error) {
c.setOrUpdate(func() {
delNum, err = c.data.sRem(key, items...)
})
return
}
func (c *ctx) SPop(key string) (item interface{}, err error) {
c.setOrUpdate(func() {
item, err = c.data.sPop(key)
})
return
}
func (c *ctx) SRandMember(key string) (item interface{}, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if c.data == nil {
return
}
return c.data.sRandMember(key)
}
func (c *ctx) HSet(key, field string, value interface{}) (isCreate bool, err error) {
c.setOrUpdate(func() {
val, exists := c.data[key]
if !exists {
isCreate = true
c.data[key] = Hash{
field: value,
}
return
}
if _, ok := val.(Hash); !ok {
err = ErrType
return
}
isCreate = c.data[key].(Hash).set(field, value)
})
return
}
func (c *ctx) HMSet(key string, kv Hash) (err error) {
if len(kv) < 1 {
return
}
c.setOrUpdate(func() {
value, exists := c.data[key]
if !exists {
c.data[key] = kv
return
}
if _, ok := value.(Hash); !ok {
err = ErrType
return
}
c.data[key].(Hash).mset(kv)
})
return
}
func (c *ctx) HGet(key, field string) (value interface{}, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if c.data == nil {
return
}
val, exists := c.data[key]
if !exists {
return
}
v, ok := val.(Hash)
if !ok {
err = ErrType
return
}
value, _ = v.get(field)
return
}
func (c *ctx) HGetAll(key string) (value Hash, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if len(c.data) < 1 {
return
}
val, exists := c.data[key]
if !exists {
return
}
if _, ok := val.(Hash); !ok {
err = ErrType
return
}
value = c.data[key].(Hash).getall()
return
}
func (c *ctx) HDel(key string, fields ...string) (delNum int, err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if len(c.data) < 1 {
return
}
value, exists := c.data[key]
if !exists {
return
}
if _, ok := value.(Hash); !ok {
err = ErrType
return
}
delNum = c.data[key].(Hash).del(fields...)
return
}
func (c *ctx) HIncrBy(key string, field string, value int64) (newValue int64, err error) {
c.setOrUpdate(func() {
val, exists := c.data[key]
if !exists {
c.data[key] = Hash{
field: value,
}
newValue = value
return
}
if _, ok := val.(Hash); !ok {
err = ErrType
return
}
newValue, err = c.data[key].(Hash).incrBy(field, value)
})
return
}
func (c *ctx) HLen(key string) (length int, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if len(c.data) < 1 {
return
}
value, exists := c.data[key]
if !exists {
return
}
val, ok := value.(Hash)
if !ok {
err = ErrType
return
}
length = val.len()
return
}
func (c *ctx) HSetNx(key, field string, value interface{}) (ok bool, err error) {
c.setOrUpdate(func() {
val, exists := c.data[key]
if !exists {
ok = true
c.data[key] = Hash{
field: value,
}
return
}
if _, yes := val.(Hash); !yes {
err = ErrType
return
}
ok = c.data[key].(Hash).setnx(field, value)
})
return
}
func (c *ctx) HSAdd(key, field string, items ...interface{}) (newNum int, err error) {
if len(items) < 1 {
return
}
c.setOrUpdate(func() {
value, exists := c.data[key]
if !exists {
newNum = len(items)
s := make(set, len(items))
s.add(items...)
c.data[key] = Hash{
field: s,
}
return
}
if _, ok := value.(Hash); !ok {
err = ErrType
return
}
newNum, err = c.data[key].(Hash).sAdd(field, items...)
})
return
}
func (c *ctx) HSCard(key, field string) (total int, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
value, exists := c.data[key]
if !exists {
return
}
val, ok := value.(Hash)
if !ok {
err = ErrType
return
}
return val.sCard(field)
}
func (c *ctx) HSMembers(key, field string) (items []interface{}, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
value, exists := c.data[key]
if !exists {
return
}
val, ok := value.(Hash)
if !ok {
err = ErrType
return
}
return val.sMembers(field)
}
func (c *ctx) HSIsMember(key, field string, item interface{}) (isMem bool, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
value, exists := c.data[key]
if !exists {
return
}
val, ok := value.(Hash)
if !ok {
err = ErrType
return
}
return val.sIsMember(field, item)
}
func (c *ctx) HSRem(key, field string, items ...interface{}) (delNum int, err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if len(c.data) < 1 {
return
}
value, exists := c.data[key]
if !exists {
return
}
if _, ok := value.(Hash); !ok {
err = ErrType
return
}
return c.data[key].(Hash).sRem(field, items...)
}
func (c *ctx) HSPop(key, field string) (item interface{}, err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if len(c.data) < 1 {
return
}
value, exists := c.data[key]
if !exists {
return
}
if _, ok := value.(Hash); !ok {
err = ErrType
return
}
return c.data[key].(Hash).sPop(field)
}
func (c *ctx) HSRandMember(key, field string) (item interface{}, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
value, exists := c.data[key]
if !exists {
return
}
val, ok := value.(Hash)
if !ok {
err = ErrType
return
}
return val.sRandMember(field)
}
func (c *ctx) HSetBit(key, field string, offset uint16, val bool) (oldValue bool, err error) {
c.setOrUpdate(func() {
value, exists := c.data[key]
if !exists {
if !val {
return
}
h := Hash{}
oldValue, _ = h.setBit(field, offset, val)
c.data[key] = h
return
}
if _, ok := value.(Hash); !ok {
err = ErrType
return
}
oldValue, err = c.data[key].(Hash).setBit(field, offset, val)
})
return
}
func (c *ctx) HGetBit(key, field string, offset uint16) (value bool, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if len(c.data) < 1 {
return
}
val, exists := c.data[key]
if !exists {
return
}
v, ok := val.(Hash)
if !ok {
err = ErrType
return
}
return v.getBit(field, offset)
}
func (c *ctx) HHasBit(key, field string) (has bool, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if len(c.data) < 1 {
return
}
val, exists := c.data[key]
if !exists {
return
}
v, ok := val.(Hash)
if !ok {
err = ErrType
return
}
return v.hasBit(field)
}
func (c *ctx) HBitCount(key, field string) (num int, err error) {
c.mutex.RLock()
defer c.mutex.RUnlock()
if len(c.data) < 1 {
return
}
val, exists := c.data[key]
if !exists {
return
}
v, ok := val.(Hash)
if !ok {
err = ErrType
return
}
return v.bitCount(field)
}
/************************************/
/***** GOLANG.ORG/X/NET/CONTEXT *****/
/************************************/
func (c *ctx) Deadline() (deadline time.Time, ok bool) {
return
}
func (c *ctx) Done() <-chan struct{} {
return nil
}
func (c *ctx) Err() error {
return nil
}
func (c *ctx) Value(key interface{}) interface{} {
if k, ok := key.(string); ok {
v, exists := c.Get(k)
if exists {
return v
}
}
return nil
}