You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/integrate/redis-data-integration/data-pipelines/transform-examples/redis-expiration-example.md
+63-2Lines changed: 63 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -49,10 +49,12 @@ output:
49
49
language: jmespath
50
50
```
51
51
52
-
Settings the expiration according to a field that contains a date, datetime, or timestamp value is also possible, but it depends on the source database and the data types it supports.
52
+
## Dynamic expiration time based on a date, datetime, or timestamp field
53
53
54
+
Settings the expiration according to a field that contains a date, datetime, or timestamp value is also possible, but it depends on the source database and the data types it supports. Please refer to the examples below for your specific source database and data type.
55
+
56
+
{{< expand "Oracle examples" >}}
54
57
55
-
### Oracle examples
56
58
The transformation depends on the data type of the field in the source database:
57
59
58
60
- `DATE`- represented by debezium as 64-bit integer representing the milliseconds since epoch
@@ -100,3 +102,62 @@ The transformation depends on the data type of the field in the source database:
100
102
expression: CASE WHEN expire_seconds < 0 THEN -expire_seconds ELSE -1 END
101
103
language: sql
102
104
```
105
+
{{< /expand >}}
106
+
107
+
108
+
{{< expand "SQL Server examples" >}}
109
+
SQL Server supports the following date and time data types:
110
+
111
+
- `date` - represented in Debezium as number of days since epoch (1970-01-01). Please note that due to the lack of time information, this method is not very accurate.
112
+
```yaml
113
+
output:
114
+
- uses: redis.write
115
+
with:
116
+
data_type: hash
117
+
expire:
118
+
# We calculate the number of seconds for the amount of days and subtract the current time in seconds since epoch.
- `datetime2`- similar to `datetime` but with higher precision. For `datetime2(0-3)` the representation is the same as for `datetime`. For `datetime2(4-6)` it is the number of microseconds since epoch. and for `datetime2(7)` it is the number of nanoseconds since epoch. You can use the same approach as for `datetime` but you need to divide by 1000, 1000000 or 1000000000 depending on the precision.
135
+
136
+
- `time`- the time of milliseconds since midnight.
137
+
```yaml
138
+
output:
139
+
- uses: redis.write
140
+
with:
141
+
data_type: hash
142
+
expire:
143
+
# We convert the time to seconds and subtract the current time in seconds since midnight.
144
+
expression: (event_time / 1000.0) -
145
+
(
146
+
CAST(strftime('%H', 'now') AS INTEGER) * 3600 +
147
+
CAST(strftime('%M', 'now') AS INTEGER) * 60 +
148
+
CAST(strftime('%S', 'now') AS INTEGER)
149
+
)
150
+
language: sql
151
+
```
152
+
- `datetimeoffset`- represented as a timestamp with timezone information, where the timezone is GMT
153
+
```yaml
154
+
output:
155
+
- uses: redis.write
156
+
with:
157
+
data_type: hash
158
+
expire:
159
+
# We convert the time to seconds and subtract the current time in seconds since epoch.
0 commit comments