Skip to content

Instantly share code, notes, and snippets.

@tzach
Last active July 31, 2020 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzach/7aa58d9e0882654450d2979e7a8d3091 to your computer and use it in GitHub Desktop.
Save tzach/7aa58d9e0882654450d2979e7a8d3091 to your computer and use it in GitHub Desktop.
CREATE KEYSPACE mykeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;
USE mykeyspace;
CREATE TABLE heartrate_ttl (
pet_chip_id uuid,
time timestamp,
heart_rate int,
PRIMARY KEY (pet_chip_id, time))
WITH default_time_to_live = 604800;
ALTER TABLE heartrate_ttl WITH default_time_to_live = 3600;
INSERT INTO heartrate_ttl(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04 07:01:00', 100);
INSERT INTO heartrate_ttl(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04 07:02:00', 103);
INSERT INTO heartrate_ttl(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04 07:03:00', 130);
INSERT INTO heartrate_ttl(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04 07:04:00', 131);
UPDATE heartrate_ttl USING TTL 2000 SET heart_rate=131 WHERE pet_chip_id=123e4567-e89b-12d3-a456-426655440b23 AND time = '2019-03-04 07:04:00';
SELECT pet_chip_id,time, heart_rate, TTL(heart_rate) from heartrate_ttl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment