From bac2c2afd27644aec0bd39503097efd802b05831 Mon Sep 17 00:00:00 2001 From: Jan Hecking Date: Fri, 12 Aug 2016 15:00:40 +0800 Subject: [PATCH] convert expiry time to TTL in seconds in batch & query result Fixes aerospike/aerospike-client-ruby#38. --- lib/aerospike/command/batch_command_get.rb | 8 ++++---- lib/aerospike/query/stream_command.rb | 2 +- spec/aerospike/client_spec.rb | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/aerospike/command/batch_command_get.rb b/lib/aerospike/command/batch_command_get.rb index 1cd9d279..e3a70b23 100644 --- a/lib/aerospike/command/batch_command_get.rb +++ b/lib/aerospike/command/batch_command_get.rb @@ -58,10 +58,10 @@ def parse_record_results(receive_size) # If cmd is the end marker of the response, do not proceed further return false if (info3 & INFO3_LAST) == INFO3_LAST - generation = @data_buffer.read_int32(6).ord - expiration = @data_buffer.read_int32(10).ord - field_count = @data_buffer.read_int16(18).ord - op_count = @data_buffer.read_int16(20).ord + generation = @data_buffer.read_int32(6) + expiration = Aerospike.TTL(@data_buffer.read_int32(10)) + field_count = @data_buffer.read_int16(18) + op_count = @data_buffer.read_int16(20) key = parse_key(field_count) item = @key_map[key.digest] diff --git a/lib/aerospike/query/stream_command.rb b/lib/aerospike/query/stream_command.rb index a33e1cdf..a88d64dd 100644 --- a/lib/aerospike/query/stream_command.rb +++ b/lib/aerospike/query/stream_command.rb @@ -53,7 +53,7 @@ def parse_record_results(receive_size) return false if (info3 & INFO3_LAST) == INFO3_LAST generation = @data_buffer.read_int32(6) - expiration = @data_buffer.read_int32(10) + expiration = Aerospike.TTL(@data_buffer.read_int32(10)) field_count = @data_buffer.read_int16(18) op_count = @data_buffer.read_int16(20) key = parse_key(field_count) diff --git a/spec/aerospike/client_spec.rb b/spec/aerospike/client_spec.rb index 7be611c4..d0e00c94 100644 --- a/spec/aerospike/client_spec.rb +++ b/spec/aerospike/client_spec.rb @@ -623,8 +623,8 @@ def cluster_seeds(client) key3 = Support.gen_random_key bin = Aerospike::Bin.new('bin', 'value') - client.put(key1, bin) - client.put(key3, bin) + client.put(key1, bin, ttl: 1000) + client.put(key3, bin, ttl: 1000) records = client.batch_get_header([key1, key2, key3]) @@ -633,12 +633,14 @@ def cluster_seeds(client) expect(records[0].key).to eq key1 expect(records[0].bins).to be nil expect(records[0].generation).to be 1 + expect(records[0].expiration).to be_within(10).of(1000) expect(records[1]).to be nil expect(records[2].key).to eq key3 expect(records[2].bins).to be nil expect(records[2].generation).to be 1 + expect(records[2].expiration).to be_within(10).of(1000) end