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
|
# File 'lib/redis/connection/memory.rb', line 673
def sscan(key, start_cursor, *args)
data_type_check(key, ::Set)
return ["0", []] unless data[key]
match = "*"
count = 10
if args.size.odd?
raise_argument_error('sscan')
end
if idx = args.index("MATCH")
match = args[idx + 1]
end
if idx = args.index("COUNT")
count = args[idx + 1]
end
start_cursor = start_cursor.to_i
cursor = start_cursor
next_keys = []
if start_cursor + count >= data[key].length
next_keys = (data[key].to_a)[start_cursor..-1]
cursor = 0
else
cursor = start_cursor + count
next_keys = (data[key].to_a)[start_cursor..cursor-1]
end
filtered_next_keys = next_keys.select{ |k,v| File.fnmatch(match, k)}
result = filtered_next_keys.flatten.map(&:to_s)
return ["#{cursor}", result]
end
|