Skip to content

DOC-3983: add HFE examples to the hash tutorial #66

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 2 commits into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/ds/hashes.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,39 @@ HINCRBY bike:1 price 100
HINCRBY bike:1 price -100
```

New in [Redis Community Edition version 7.4](https://hub.docker.com/layers/redis/redis-stack/7.4.0-v0/images/sha256-3e3c86603a81712d1311bc619ad124de15b2dca2b50722f23a4502b4d4054ba8) is the ability set the expiration time or the remaining time-to-live (TTL) for individual hash fields. This is called hash field expiration (HFE). HFE works just like [key expiration](https://redis.io/docs/latest/develop/use/keyspace/?utm_source=redisinsight&utm_medium=main&utm_campaign=tutorials#key-expiration) and includes the following commands:

- `hexpire` - set an expiration (time-to-live or TTL) in seconds on a hash key's field(s).
- `hexpireat` - set a TTL as an absolute Unix timestamp (seconds since Unix epoch) on a hash key's field(s).
- `hexpiretime` - returns the absolute Unix timestamp (seconds since Unix epoch) at which the hash key's field(s) will expire.
- `hpersist` - remove expirations from a hash key's field(s).
- `hpexpire` - set an expiration (time-to-live or TTL) in milliseconds on a hash key's field(s).
- `hpexpireat` - set a TTL as an absolute Unix timestamp (milliseconds since Unix epoch) on a hash key's field(s).
- `hpexpiretime` - returns the absolute Unix timestamp (milliseconds since Unix epoch) at which the the hash key's field(s) will expire.
- `hpttl` - returns the remaining TTL in milliseconds of a hash key's field(s).
- `httl` - returns the remaining TTL in seconds of a hash key's field(s).

```redis HFE example 1
HSET hash field1 "foo" field2 "bar" field3 "baz"
HEXPIRE hash 10 FIELDS 1 field2
HTTL hash FIELDS 1 field2
```

```redis HFE example 1 cont'd
HTTL hash FIELDS 1 field2
HGETALL hash
```

```redis HFE example 2
HSET hash field1 "foo" field2 "bar" field3 "baz"
HEXPIRE hash 10 FIELDS 2 field1 field3
HTTL hash FIELDS 2 field1 field3
HPERSIST hash FIELDS 1 field3
HTTL hash FIELDS 2 field1 field3
```

```redis HFE example 2 cont'd
HGETALL hash
```

See [here](https://redis.io/docs/data-types/hashes?utm_source=redisinsight&utm_medium=main&utm_campaign=tutorials) for the hash type reference page, and [here](https://redis.io/commands/?group=hash?utm_source=redisinsight&utm_medium=main&utm_campaign=tutorials) for the entire set of Redis hash commands.