Stitching Keys TTL
Stitching Keys TTL in Redis.
Stitching Keys TTL#
The TTL is a time-to-live or expiry time set to a stitching key. When the key exceeds the expiry time, it automatically deletes the key in Redis.
This is assigned to an individual stitching key to reduce the unnecessary load on the redis.
Stitching Keys Expiry Time#
The tracking of the expiration time of the keys is important due to the following reasons:
1. Pre-expiry time: If the stitching keys are deleted before the expiry time, this might lead to inconsistency in data or incorrect results for the requested queries.
2. Post-expiry time: If the stitching keys are not deleted after the expiry time, this might lead to unexpected behavior and inconsistency in data.
When the stitching keys are not deleted automatically, it is recommended to delete them manually by setting the TTL for the stitching key using Redis-cli.
Identify the Stitching Keys Expiry Time#
Follow the below steps to identify the stitching key's expiry time:
1. Check the value for the below consul key:
Service/datareceiver/delay/request/queue/threshold
Note:
- By default, it will be 300.
- Depending on the key value, the 'txn-request' will wait for the response. If not, redis will discard it.
You can use any one of the below two options:
Option A: To check the status of TTL seconds, execute the below command:
<redis_IP:redis_Port>> ttl /requests/<stitchingId>
For example:
19x.xyz.xy.xyz:7003> ttl /requests/8000000 (integer) 100
Note:
- Copy the stitching ID from the data-receiver.
- Make sure the output value (expiry time) should be decreasing.
Option B: Inside the Redis container, log in to redis-cli by the below command:
redis-cli -c --tls --cert /etc/redis.crt --key /etc/redis.key --cacert /etc/appnomic-rootca.crt -h <redis_ip> -p <redis_port>
For example:
redis-cli -c --tls --cert /etc/redis.crt --key /etc/redis.key --cacert /etc/appnomic-rootca.crt -h 19x.xyz.xy.xyz -p 7001
2. To obtain the stitching keys, execute the below command:
<redis_IP:redis_Port> keys */requests/<stitchingId>/*
For example:
19x.xyz.xy.xyz:7001> /requests/800000
3. To check the idle time of the respective key, execute the below command:
<redis_IP:redis_Port> OBJECT IDLETIME <stitchingid_key>
For example:
19x.xyz.xy.xyz:7001> OBJECT IDLETIME <stitchingid_key>
Note: Redis keys are not deleted if the above command (idle time) output exceeds the consul key value.
Delete the Stitching Keys#
To delete the post-expiry keys (for which TTL is not applied) manually, follow the below steps.
1. Copy the redis-client build from the location below and place it in the a1home path (unzip this build).
redis-client.zip
2. Import a certificate for the Redis server into the Java keystore by executing the below command:
keytool -import -trustcacerts -keystore /usr/lib/jvm/jre/lib/security/cacerts -storepass changeit -noprompt -alias redis -file <a1home_path>/Appsone_Service/data/cert/redis.crt
3. Inside each redis container, get the redis keys pattern and save the output in the text file by using the below commands:
redis-cli --tls --cert /etc/redis.crt --key /etc/redis --cacert /etc/appnomic-rootca.crt -h <redis_ip> -p <redis port> keys */requests/<stitchingId>/* > /tmp/logs/7001keys.txt
redis-cli --tls --cert /etc/redis.crt --key /etc/redis --cacert /etc/appnomic-rootca.crt -h <redis_ip> -p 7002 keys /requests/<stitchingId>/* > /tmp/logs/7002keys.txt
redis-cli --tls --cert /etc/redis.crt --key /etc/redis --cacert /etc/appnomic-rootca.crt -h <redis_ip> -p 7003 keys /requests/<stitchingId>/* > /tmp/logs/7003keys.txt
redis-cli --tls --cert /etc/redis.crt --key /etc/redis --cacert /etc/appnomic-rootca.crt -h <redis_ip> -p 7004 keys /requests/<stitchingId>/* > /tmp/logs/7004keys.txt
redis-cli --tls --cert /etc/redis.crt --key /etc/redis --cacert /etc/appnomic-rootca.crt -h <redis_ip> -p 7005 keys /requests/<stitchingId>/* > /tmp/logs/7005keys.txt
redis-cli --tls --cert /etc/redis.crt --key /etc/redis --cacert /etc/appnomic-rootca.crt -h <redis_ip> -p 7006 keys /requests/<stitchingId>/* > /tmp/logs/7006keys.txt
4. Exit the Redis container and wait for a while (minimum of 5 min).
5. The text files will be created in centralized logs of Redis. Based on the container ID, check each Redis node in centralized logs.
6. Open the text file in the vi editor and execute the below command:
:%norm A,
:%norm A (After A there should be space)
:%norm A,
or
:%s/$/\*/g
7. Switch to the directory by using the below command:
cd /<a1home_path>/redis-client/
8. To delete the keys, execute the below command:
java -cp lib/*:. RedisClient
<redis_ip>:7001,<redis_ip>:7002,<redis_ip>:7003,<redis_ip>:7004,<redis_ip>:7005,<redis_ip>:7006 "" "" true .. /centralized_logs/redis-node1/7002key.txt delete
For example:
<19x.xyz.xy.xyz>:7001,<19x.xyz.xy.xyz>:7002,<19x.xyz.xy.xyz>:7003,<19x.xyz.xy.xyz>:7004,<19x.xyz.xy.xyz>:7005,<19x.xyz.xy.xyz>:7006 "" "" true /corpapp/the customer/centralized_logs/redis-node1/7002key.txt delete
Redis Troubleshooting#
Redis troubleshooting is the process of detecting and resolving the issue in Redis. The troubleshooting involves many issues such as performance, replication, data consistency, security, etc.
To troubleshoot Redis, you have to log in to redis-cli.
Refer to Troubleshooting Guide: Redis Issues.