-
Notifications
You must be signed in to change notification settings - Fork 27
docs: Add HTTL command reference page #513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a4a8e54
Initial plan
Copilot 518e95e
Add HTTL command documentation page
Copilot 1d4c10b
Remove Simple error reply section and Parameters table from HTTL docs
Copilot 25b6c21
Update HTTL docs: remove HPTTL note, add FIELDTTL to related commands
Copilot 37a0583
Fix FIELDTTL link to point to generic/fieldttl.md
Copilot 8c8484f
Fix Array reply link to use valkey.io/topics/protocol/#arrays
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| --- | ||
| description: "Learn how to use the HTTL command to query the remaining TTL of individual fields within a Redis hash, enabling granular cache management." | ||
| --- | ||
|
|
||
| import PageTitle from '@site/src/components/PageTitle'; | ||
|
|
||
| # HTTL | ||
|
|
||
| <PageTitle title="Redis HTTL Command (Documentation) | Dragonfly" /> | ||
|
|
||
| ## Syntax | ||
|
|
||
| HTTL key FIELDS numfields field [field ...] | ||
|
|
||
| **Time complexity:** O(N) where N is the number of fields being queried | ||
|
|
||
| **ACL categories:** @read, @hash, @fast | ||
|
|
||
| Returns the remaining Time-To-Live (TTL) in seconds for one or more fields of a hash stored at `key`. | ||
| This allows you to inspect when individual hash fields will expire without modifying them. | ||
|
|
||
| Unlike `TTL`, which operates at the key level, `HTTL` operates at the field level. | ||
| Field-level expiry is set via [`HEXPIRE`](./hexpire.md) or [`HSETEX`](./hsetex.md). | ||
|
|
||
| ## Return | ||
|
|
||
| [Array reply](https://valkey.io/topics/protocol/#arrays): an array of integer replies, one per field, in the same order as the fields were requested: | ||
|
|
||
| - Integer reply: `-2` if the field does not exist in the hash, or if the hash key itself does not exist. | ||
| - Integer reply: `-1` if the field exists but has no associated expiration (it persists indefinitely). | ||
| - Integer reply: a positive integer representing the remaining TTL in seconds. | ||
|
|
||
| ## Examples | ||
|
|
||
| **Fields with no expiry, one non-existent field:** | ||
|
|
||
| ```shell | ||
| dragonfly> HSET myhash field1 "hello" field2 "world" | ||
| (integer) 2 | ||
| dragonfly> HTTL myhash FIELDS 3 field1 field2 nosuchfield | ||
| 1) (integer) -1 | ||
| 2) (integer) -1 | ||
| 3) (integer) -2 | ||
| ``` | ||
|
|
||
| **Setting an expiry and checking the remaining TTL:** | ||
|
|
||
| ```shell | ||
| dragonfly> HEXPIRE myhash 30 FIELDS 1 field1 | ||
| 1) (integer) 1 | ||
| dragonfly> HTTL myhash FIELDS 2 field1 field2 | ||
| 1) (integer) 29 | ||
| 2) (integer) -1 | ||
| ``` | ||
|
|
||
| **Key does not exist — all fields return `-2`:** | ||
|
|
||
| ```shell | ||
| dragonfly> HTTL no-key FIELDS 2 field1 field2 | ||
| 1) (integer) -2 | ||
| 2) (integer) -2 | ||
| ``` | ||
|
|
||
| **Wrong key type:** | ||
|
|
||
| ```shell | ||
| dragonfly> SET mystring "value" | ||
| "OK" | ||
| dragonfly> HTTL mystring FIELDS 1 field1 | ||
| (error) WRONGTYPE Operation against a key holding the wrong kind of value | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - `HTTL` is a read-only command and does not modify the hash or any field TTLs. | ||
| - The reported TTL reflects the time remaining at the moment the command is executed. For precise expiry management, consider the clock resolution on the server. | ||
| - To remove an expiry from a field (make it persist), re-set the field without an expiry using [`HSET`](./hset.md). | ||
|
|
||
| ## Related Commands | ||
|
|
||
| - [`HEXPIRE`](./hexpire.md) — Set a TTL on one or more hash fields. | ||
| - [`FIELDTTL`](../generic/fieldttl.md) — Retrieve the TTL of a specific field. | ||
| - [`HSETEX`](./hsetex.md) — Set hash field values along with a TTL. | ||
| - [`HSET`](./hset.md) — Set hash field values (no expiry). | ||
| - [`HGETALL`](./hgetall.md) — Retrieve all fields and values of a hash. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.