Just set the TTL on a row

前端 未结 3 1398
迷失自我
迷失自我 2021-01-02 05:29

Using Java, can I scan a Cassandra table and just update the TTL of a row? I don\'t want to change any data. I just want to scan Cassandra table and set TTL of a few rows.

3条回答
  •  情深已故
    2021-01-02 06:11

    You can't only update TTL of a row. You have to update or re-insert all the column.

    You can select all the regular column and the primary keys column then update the regular columns with primary keys or re-insert using TTL in second

    In Java you can calculate TTL in second from a date using below method.

    public static long ttlFromDate(Date ttlDate) throws Exception {
        long ttl = (ttlDate.getTime() - System.currentTimeMillis()) / 1000;
        if (ttl < 1) {
            throw new Exception("Invalid ttl date");
        }
        return ttl;
    }
    

提交回复
热议问题