K - Key type, matching the field-name type of the connection's codec.@Experimental public class HashImport<K> extends Object implements AutoCloseable
HIMPORT command family.
Create a fieldset once and pass it to every himportSet call that writes those fields, supplying only the values. The
field names themselves are declared to the server on first use and re-declared transparently across reconnects, pooled
connections, and new cluster nodes, so no prepare step is ever issued by the caller.
Use of(String...) for String-keyed connections, or of(Function, Object...) to derive the fieldset
name for another key type. Field names must be non-empty and free of duplicates.
A fieldset is safe to share across threads and connections. Close it when the import is finished to release
its server-side state; a fieldset that is never closed holds that state until the connections it was used on are closed.
Imports already issued when close() is called still complete, so try-with-resources is safe with the synchronous,
asynchronous, and reactive APIs alike.
try (HashImport<String> fieldset = HashImport.of("name", "email")) {
redis.himportSet("user:1", fieldset, "alice", "alice@example.com");
redis.himportSet("user:2", fieldset, "bob", "bob@example.com");
}
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Discard this fieldset, releasing its server-side state on every connection it was used on.
|
K[] |
fields()
Return the field names, in the order values are supplied to
himportSet. |
K |
name()
Return the generated name identifying this fieldset on the server.
|
static <K> HashImport<K> |
of(Function<Long,K> idCodec,
K... fields)
Create a fieldset for a key type other than
String, naming it by applying idCodec to a generated sequence
number. |
static HashImport<String> |
of(String... fields)
Create a fieldset for
String-keyed connections. |
int |
size()
Return the number of fields, which is the number of values every
himportSet call must supply. |
String |
toString() |
public static HashImport<String> of(String... fields)
String-keyed connections. The fieldset name is generated and unique per instance.fields - the field names, in the order values are supplied to himportSet; must not be null, empty,
or contain null or duplicate elements.fields.IllegalArgumentException - if fields is null, empty, or contains null or duplicate
elements.@SafeVarargs public static <K> HashImport<K> of(Function<Long,K> idCodec, K... fields)
String, naming it by applying idCodec to a generated sequence
number.
idCodec must map distinct sequence numbers to distinct names: two live fieldsets sharing a name also share their
server-side state, and closing either releases it for both.
K - Key type.idCodec - maps a generated sequence number to a fieldset name, must not be null and must produce a distinct
name per invocation.fields - the field names, in the order values are supplied to himportSet; must not be null, empty,
or contain null or duplicate elements.fields.IllegalArgumentException - if idCodec is null or returns null, or if fields is
null, empty, or contains null or duplicate elements.public K name()
null.public K[] fields()
himportSet.public int size()
himportSet call must supply.public void close()
Further imports are rejected from the moment this returns: a subsequent himportSet fails with an
IllegalStateException. Imports already issued are not cancelled and still complete, so this may return before the
state has actually been released.
Release is best-effort and does not report failures. The state is released in any case when a connection closes, so closing a fieldset is not required for correctness — but on long-lived and pooled connections an unclosed fieldset holds its state for the life of those connections. Calling this more than once has no further effect.
close in interface AutoCloseableCopyright © 2026 lettuce.io. All rights reserved.