File tree Expand file tree Collapse file tree 10 files changed +642
-1
lines changed Expand file tree Collapse file tree 10 files changed +642
-1
lines changed Original file line number Diff line number Diff line change
1
+ import pytest
2
+ import time
3
+ from upstash_redis import Redis
4
+
5
+
6
+ @pytest .fixture (autouse = True )
7
+ def flush_hash (redis : Redis ):
8
+ hash_name = "myhash"
9
+ redis .delete (hash_name )
10
+
11
+
12
+ def test_hexpireat_sets_expiry (redis : Redis ):
13
+ hash_name = "myhash"
14
+ field = "field1"
15
+ value = "value1"
16
+
17
+ redis .hset (hash_name , field , value )
18
+ future_timestamp = int (time .time ()) + 2
19
+ assert redis .hexpireat (hash_name , field , future_timestamp )[0 ] == 1
20
+
21
+ time .sleep (3 )
22
+ assert redis .hexists (hash_name , field ) == 0
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ import time
3
+ from upstash_redis import Redis
4
+
5
+
6
+ @pytest .fixture (autouse = True )
7
+ def flush_hash (redis : Redis ):
8
+ hash_name = "myhash"
9
+ redis .delete (hash_name )
10
+
11
+
12
+ def test_hexpiretime_returns_correct_expiry (redis : Redis ):
13
+ hash_name = "myhash"
14
+ field = "field1"
15
+ value = "value1"
16
+
17
+ redis .hset (hash_name , field , value )
18
+ redis .hexpire (hash_name , field , 5 )
19
+ expiry_time = redis .hexpiretime (hash_name , [field ])[0 ]
20
+
21
+ assert expiry_time > int (time .time ())
22
+ assert expiry_time <= int (time .time ()) + 5
23
+
24
+
25
+ def test_hexpiretime_returns_minus1_if_no_expiry (redis : Redis ):
26
+ hash_name = "myhash"
27
+ field = "field1"
28
+ value = "value1"
29
+
30
+ redis .hset (hash_name , field , value )
31
+ assert redis .hexpiretime (hash_name , [field ])[0 ] == - 1
32
+
33
+
34
+ def test_hexpiretime_returns_minus2_if_field_does_not_exist (redis : Redis ):
35
+ hash_name = "myhash"
36
+ field = "field1"
37
+
38
+ assert redis .hexpiretime (hash_name , [field ])[0 ] == - 2
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ from upstash_redis import Redis
3
+
4
+
5
+ @pytest .fixture (autouse = True )
6
+ def flush_hash (redis : Redis ):
7
+ hash_name = "myhash"
8
+ redis .delete (hash_name )
9
+
10
+
11
+ def test_hpersist_removes_expiry (redis : Redis ):
12
+ hash_name = "myhash"
13
+ field = "field1"
14
+ value = "value1"
15
+
16
+ redis .hset (hash_name , field , value )
17
+ redis .hexpire (hash_name , field , 500 )
18
+ ttl_before = redis .httl (hash_name , field )
19
+ assert ttl_before [0 ] > 0
20
+
21
+ redis .hpersist (hash_name , field )
22
+ ttl_after = redis .httl (hash_name , field )
23
+ assert ttl_after == [- 1 ]
24
+
25
+
26
+ def test_hpersist_does_nothing_if_no_expiry (redis : Redis ):
27
+ hash_name = "myhash"
28
+ field = "field1"
29
+ value = "value1500"
30
+
31
+ redis .hset (hash_name , field , value )
32
+ assert redis .hpersist (hash_name , field ) == [- 1 ]
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ import time
3
+ from upstash_redis import Redis
4
+
5
+
6
+ @pytest .fixture (autouse = True )
7
+ def flush_hash (redis : Redis ):
8
+ hash_name = "myhash"
9
+ redis .delete (hash_name )
10
+
11
+
12
+ def test_hpexpire_sets_expiry_in_milliseconds (redis : Redis ):
13
+ hash_name = "myhash"
14
+ field = "field1"
15
+ value = "value1"
16
+
17
+ redis .hset (hash_name , field , value )
18
+ assert redis .hpexpire (hash_name , field , 500 ) == [1 ]
19
+
20
+ time .sleep (1 )
21
+ assert redis .hget (hash_name , field ) is None
22
+
23
+
24
+ def test_hpexpire_does_not_set_expiry_if_field_does_not_exist (redis : Redis ):
25
+ hash_name = "myhash"
26
+ field = "field1"
27
+
28
+ assert redis .hpexpire (hash_name , field , 500 ) == [- 2 ]
29
+
30
+
31
+ def test_hpexpire_overwrites_existing_expiry (redis : Redis ):
32
+ hash_name = "myhash"
33
+ field = "field1"
34
+ value = "value1"
35
+
36
+ redis .hset (hash_name , field , value )
37
+ redis .hpexpire (hash_name , field , 1000 )
38
+ assert redis .hpexpire (hash_name , field , 2000 ) == [1 ]
39
+
40
+ time .sleep (2.5 )
41
+ assert redis .hget (hash_name , field ) is None
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ import time
3
+ from upstash_redis import Redis
4
+
5
+
6
+ @pytest .fixture (autouse = True )
7
+ def flush_hash (redis : Redis ):
8
+ hash_name = "myhash"
9
+ redis .delete (hash_name )
10
+
11
+
12
+ def test_hpexpireat_sets_expiry_in_milliseconds (redis : Redis ):
13
+ hash_name = "myhash"
14
+ field = "field1"
15
+ value = "value1"
16
+
17
+ redis .hset (hash_name , field , value )
18
+ future_timestamp_ms = int (time .time () * 1000 ) + 500
19
+ assert redis .hpexpireat (hash_name , field , future_timestamp_ms ) == [1 ]
20
+
21
+ time .sleep (1 )
22
+ assert redis .hget (hash_name , field ) is None
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ import time
3
+ from upstash_redis import Redis
4
+
5
+
6
+ @pytest .fixture (autouse = True )
7
+ def flush_hash (redis : Redis ):
8
+ hash_name = "myhash"
9
+ redis .delete (hash_name )
10
+
11
+
12
+ def test_hpexpiretime_returns_correct_expiry (redis : Redis ):
13
+ hash_name = "myhash"
14
+ field = "field1"
15
+ value = "value1"
16
+
17
+ redis .hset (hash_name , field , value )
18
+ redis .hpexpire (hash_name , field , 500 )
19
+ expiry_time_ms = redis .hpexpiretime (hash_name , [field ])[0 ]
20
+
21
+ assert expiry_time_ms > 0
22
+ assert expiry_time_ms <= int (time .time () * 1000 ) + 1000
23
+
24
+
25
+ def test_hpexpiretime_returns_minus1_if_no_expiry (redis : Redis ):
26
+ hash_name = "myhash"
27
+ field = "field1"
28
+ value = "value1"
29
+
30
+ redis .hset (hash_name , field , value )
31
+ assert redis .hpexpiretime (hash_name , [field ])[0 ] == - 1
32
+
33
+
34
+ def test_hpexpiretime_returns_minus2_if_field_does_not_exist (redis : Redis ):
35
+ hash_name = "myhash"
36
+ field = "field1"
37
+
38
+ assert redis .hpexpiretime (hash_name , [field ])[0 ] == - 2
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ from upstash_redis import Redis
3
+
4
+
5
+ @pytest .fixture (autouse = True )
6
+ def flush_hash (redis : Redis ):
7
+ hash_name = "myhash"
8
+ redis .delete (hash_name )
9
+
10
+
11
+ def test_hpttl_returns_correct_ttl (redis : Redis ):
12
+ hash_name = "myhash"
13
+ field = "field1"
14
+ value = "value1"
15
+
16
+ redis .hset (hash_name , field , value )
17
+ redis .hpexpire (hash_name , field , 1500 )
18
+ ttl = redis .hpttl (hash_name , [field ])[0 ]
19
+
20
+ assert ttl > 0
21
+
22
+
23
+ def test_hpttl_returns_minus1_if_no_expiry (redis : Redis ):
24
+ hash_name = "myhash"
25
+ field = "field1"
26
+ value = "value1"
27
+
28
+ redis .hset (hash_name , field , value )
29
+ assert redis .hpttl (hash_name , [field ])[0 ] == - 1
30
+
31
+
32
+ def test_hpttl_returns_minus2_if_field_does_not_exist (redis : Redis ):
33
+ hash_name = "myhash"
34
+ field = "field1"
35
+
36
+ assert redis .hpttl (hash_name , [field ])[0 ] == - 2
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ from upstash_redis import Redis
3
+
4
+
5
+ @pytest .fixture (autouse = True )
6
+ def flush_hash (redis : Redis ):
7
+ hash_name = "myhash"
8
+ redis .delete (hash_name )
9
+
10
+
11
+ def test_httl_returns_correct_ttl (redis : Redis ):
12
+ hash_name = "myhash"
13
+ field = "field1"
14
+ value = "value1"
15
+
16
+ redis .hset (hash_name , field , value )
17
+ redis .hexpire (hash_name , field , 5 )
18
+ ttl = redis .httl (hash_name , [field ])[0 ]
19
+
20
+ assert ttl > 0
21
+ assert ttl <= 5
22
+
23
+
24
+ def test_httl_returns_minus1_if_no_expiry (redis : Redis ):
25
+ hash_name = "myhash"
26
+ field = "field1"
27
+ value = "value1"
28
+
29
+ redis .hset (hash_name , field , value )
30
+ assert redis .httl (hash_name , [field ])[0 ] == - 1
31
+
32
+
33
+ def test_httl_returns_minus2_if_field_does_not_exist (redis : Redis ):
34
+ hash_name = "myhash"
35
+ field = "field1"
36
+
37
+ assert redis .httl (hash_name , [field ])[0 ] == - 2
You can’t perform that action at this time.
0 commit comments