redis/redis-rb · error · ArgumentError
fields must not be empty
Error message
fields must not be empty
What it means
himport_prepare registers a named fieldset for the HIMPORT command family as per-connection session state on the server. After flattening its *fields argument it requires at least one field name; an empty list — no arguments, a single empty array, or an empty computed list — raises ArgumentError 'fields must not be empty' client-side.
Source
Thrown at lib/redis/commands/hashes.rb:492
# other connections. See the README "Bulk hash ingestion (HIMPORT)"
# section for connection-scoping guidance. Re-preparing an existing
# +fieldset_name+ silently replaces it. Field order is preserved as
# given; it defines the positional pairing used by #himport_set.
#
# @note HIMPORT support is experimental: the client API may change in a
# future minor release without a major version bump.
#
# @example
# redis.himport_prepare("shared", ["name", "email", "age"])
# # => "OK"
#
# @param [String] fieldset_name name used by later SET and DISCARD calls
# @param [String, Array<String>] fields one or more field names
# @return [String] `"OK"`
# @api experimental
def himport_prepare(fieldset_name, *fields)
fields.flatten!(1)
raise ArgumentError, "fields must not be empty" if fields.empty?
send_command([:himport, "PREPARE", fieldset_name].concat(fields))
end
# Create or fully replace the hash at +key+ using the field list
# registered under +fieldset_name+ on this connection. Values pair
# positionally with the fields given to #himport_prepare; the value
# count must equal the field count.
#
# The fieldset must exist on the executing connection, otherwise the
# server replies with a "no such fieldset" error.
#
# @note HIMPORT support is experimental: the client API may change in a
# future minor release without a major version bump.
#
# @example
# redis.himport_set("shared:1", "shared", ["alice", "alice@example.com", "25"])
# # => "OK"View on GitHub (pinned to 2ba9010b91)
Solutions
- Pass at least one field: redis.himport_prepare('shared', 'name', 'email') or an array like redis.himport_prepare('shared', %w[name email])
- Guard dynamic lists at the construction site and raise a domain-specific error naming the empty source
- Remember fieldsets are per-connection state: after reconnect/failover re-prepare (the client auto-repairs via himport_auto_prepare unless disabled)
Example fix
# before
fields = [] # e.g. computed from user input
redis.himport_prepare('shared', fields) # ArgumentError
# after
raise ArgumentError, 'no fields selected' if fields.empty?
redis.himport_prepare('shared', *fields) Defensive patterns
Strategy: validation
Validate before calling
fields = Array(fields).flatten raise ArgumentError, 'no fields to register' if fields.empty? redis.himport_prepare(fieldset_name, *fields)
Prevention
- Validate schema lists at construction time with a domain-specific error
- Flatten and compact computed field lists before passing them
- Remember the fieldset is per-connection session state; re-prepare after reconnects
When it happens
Trigger: redis.himport_prepare('schema') with no fields; redis.himport_prepare('schema', []); a fields array built at runtime (e.g. columns.select { ... }) that matched nothing and flattens to [].
Common situations: Dynamic schemas derived from model attributes or query results that can legitimately be empty; refactoring a fixed field list into a variable without adding a guard.
Related errors
- count argument must be specified
- wrong number of arguments
- ranges must be given as start/stop pairs
- logic must be :and or :or
- value is required for the MATCH operation
AI-assisted analysis of redis/redis-rb@2ba9010b91 (2026-08-23).
Data as JSON: /api/errors/a74d72aac28c0a0c.
Report an issue: GitHub.