aerospike 记录 TTL 说明
所属分类 aerospike
浏览量 1018
写入操作可设置过期时间 , 不设置 使用 namespace 的 default-ttl
读操作不会修改
如果 某条记录 只有读 没有写的话 ,ttl会不断变小 ,直到过期
写入操作可设置不更新TTL
可设置为-1 ,Never expire 不过期 不会被逐出
TTL 为0或-1的记录不会过期或逐出
TTL 客户端主动设置,否则使用namespace的默认TTL配置
update和touch操作会更新TTL
NSUP (namespace supervisor) 线程 负责 过期 和 逐出操作。
NSUP线程周期运行, 时间间隔通过 nsup-period 参数设置
nsup-period 默认 120s
WritePolicy
public int generation;
expiration
Record expiration. Also known as ttl (time to live).
Seconds record will live before being removed by the server.
-2: Do not change ttl when record is updated. Supported by Aerospike server versions >= 3.10.1.
-1: Never expire. Supported by Aerospike server versions >= 3.1.4.
0: Default to namespace configuration variable "default-ttl" on the server.
>0: Actual ttl in seconds.
private static void runTest(IAerospikeClient client,int ttl) throws Exception{
WritePolicy policy = new WritePolicy();
policy.expiration = ttl;
String key = "ttl_test_"+ttl;
String value = key+"_"+LocalDateTime.now();
Key k = new Key(namespace, dataSetName, key);
Bin v = new Bin(bin,Value.get(value));
policy.expiration = ttl;
client.put(policy, k,v);
Record record = client.get(null, k);
System.out.println("record=" + record+",TTL="+record.getTimeToLive());
Thread.sleep(2000);
record = client.get(null, k);
System.out.println("record=" + record+",TTL="+record.getTimeToLive());
System.out.println();
}
完整测试代码
https://gitee.com/dyyx/asdemo/blob/master/src/main/java/demo/TTLTest2.java
record=(gen:8),(exp:348489010),(bins:(DATA:ttl_test_-2_2020-12-18T18:18:10.530)),TTL=2591280
record=(gen:8),(exp:348489010),(bins:(DATA:ttl_test_-2_2020-12-18T18:18:10.530)),TTL=2591278
record=(gen:8),(exp:0),(bins:(DATA:ttl_test_-1_2020-12-18T18:18:12.578)),TTL=-1
record=(gen:8),(exp:0),(bins:(DATA:ttl_test_-1_2020-12-18T18:18:12.578)),TTL=-1
record=(gen:9),(exp:348489734),(bins:(DATA:ttl_test_0_2020-12-18T18:18:14.597)),TTL=2592000
record=(gen:9),(exp:348489734),(bins:(DATA:ttl_test_0_2020-12-18T18:18:14.597)),TTL=2591998
record=(gen:5),(exp:345897836),(bins:(DATA:ttl_test_100_2020-12-18T18:18:16.616)),TTL=100
record=(gen:5),(exp:345897836),(bins:(DATA:ttl_test_100_2020-12-18T18:18:16.616)),TTL=98
record=(gen:6),(exp:345897938),(bins:(DATA:ttl_test_200_2020-12-18T18:18:18.634)),TTL=200
record=(gen:6),(exp:345897938),(bins:(DATA:ttl_test_200_2020-12-18T18:18:18.634)),TTL=198
record=(gen:7),(exp:345897938),(bins:(DATA:ttl_test_200_2020-12-18T18:18:20.651)),TTL=198
上一篇
下一篇
aerospike 某客户 stop-write 实例
aerospike 最大 TTL 限制
aerospike常见错误
写博客的好处
TCP三次握手与四次挥手
HTTPS连接过程及中间人攻击防范