1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
|
# File 'lib/redis/connection/memory.rb', line 1026
def scan(start_cursor, *args)
match = "*"
count = 10
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
data_type_check(start_cursor, Integer)
cursor = start_cursor
returned_keys = []
final_page = start_cursor + count >= keys(match).length
if final_page
previous_keys_been_deleted = (count >= keys(match).length)
start_index = previous_keys_been_deleted ? 0 : cursor
returned_keys = keys(match)[start_index..-1]
cursor = 0
else
end_index = start_cursor + (count - 1)
returned_keys = keys(match)[start_cursor..end_index]
cursor = start_cursor + count
end
return "#{cursor}", returned_keys
end
|