Skip to content

Instantly share code, notes, and snippets.

@yuta-imai
Last active September 11, 2015 11:40
Show Gist options
  • Save yuta-imai/323e5d29200b15aebf14 to your computer and use it in GitHub Desktop.
Save yuta-imai/323e5d29200b15aebf14 to your computer and use it in GitHub Desktop.
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