Last active
September 11, 2015 11:40
-
-
Save yuta-imai/323e5d29200b15aebf14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'aws-sdk-core' | |
ddb = Aws::DynamoDB::Client.new(region: "ap-northeast-1") | |
table_name = 'rangetest' | |
hash_key_str = 'test' | |
(1...100).each do |i| | |
ddb.put_item({ | |
table_name: table_name, | |
item: { | |
"group" => hash_key_str, | |
"message_id" => i | |
} | |
}) | |
end | |
# Descending | |
ddb.query({ | |
table_name: table_name, | |
limit: 5, | |
scan_index_forward:false, | |
key_conditions: { | |
"group" => { attribute_value_list: [hash_key_str], comparison_operator:"EQ"} | |
} | |
}).items.each do |item| | |
puts item["message_id"].to_i | |
end | |
# Ascending | |
ddb.query({ | |
table_name: table_name, | |
limit: 5, | |
scan_index_forward:true, | |
key_conditions: { | |
"group" => { attribute_value_list: [hash_key_str], comparison_operator:"EQ"} | |
} | |
}).items.each do |item| | |
puts item["message_id"].to_i | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment