Documentation
¶
Overview ¶
Package rhash is a database-backed hash repository. It provides methods to interact with hashmaps in the database.
Index ¶
- type DB
- func (d *DB) Delete(key string, fields ...string) (int, error)
- func (d *DB) Exists(key, field string) (bool, error)
- func (d *DB) Fields(key string) ([]string, error)
- func (d *DB) Get(key, field string) (core.Value, error)
- func (d *DB) GetMany(key string, fields ...string) (map[string]core.Value, error)
- func (d *DB) Incr(key, field string, delta int) (int, error)
- func (d *DB) IncrFloat(key, field string, delta float64) (float64, error)
- func (d *DB) Items(key string) (map[string]core.Value, error)
- func (d *DB) Len(key string) (int, error)
- func (d *DB) Scan(key string, cursor int, pattern string, count int) (ScanResult, error)
- func (d *DB) Scanner(key, pattern string, pageSize int) *Scanner
- func (d *DB) Set(key, field string, value any) (bool, error)
- func (d *DB) SetMany(key string, items map[string]any) (int, error)
- func (d *DB) SetNotExists(key, field string, value any) (bool, error)
- func (d *DB) Values(key string) ([]core.Value, error)
- type HashItem
- type ScanResult
- type Scanner
- type Tx
- func (tx *Tx) Delete(key string, fields ...string) (int, error)
- func (tx *Tx) Exists(key, field string) (bool, error)
- func (tx *Tx) Fields(key string) ([]string, error)
- func (tx *Tx) Get(key, field string) (core.Value, error)
- func (tx *Tx) GetMany(key string, fields ...string) (map[string]core.Value, error)
- func (tx *Tx) Incr(key, field string, delta int) (int, error)
- func (tx *Tx) IncrFloat(key, field string, delta float64) (float64, error)
- func (tx *Tx) Items(key string) (map[string]core.Value, error)
- func (tx *Tx) Len(key string) (int, error)
- func (tx *Tx) Scan(key string, cursor int, pattern string, count int) (ScanResult, error)
- func (tx *Tx) Scanner(key, pattern string, pageSize int) *Scanner
- func (tx *Tx) Set(key string, field string, value any) (bool, error)
- func (tx *Tx) SetMany(key string, items map[string]any) (int, error)
- func (tx *Tx) SetNotExists(key, field string, value any) (bool, error)
- func (tx *Tx) Values(key string) ([]core.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB is a database-backed hash repository. A hash (hashmap) is a field-value map associated with a key. Use the hash repository to work with individual hashmaps and their fields.
func (*DB) Delete ¶
Delete deletes one or more items from a hash. Returns the number of fields deleted. Ignores non-existing fields. Does nothing if the key does not exist or is not a hash.
func (*DB) Exists ¶
Exists checks if a field exists in a hash. If the key does not exist or is not a hash, returns false.
func (*DB) Fields ¶
Fields returns all fields in a hash. If the key does not exist or is not a hash, returns an empty slice.
func (*DB) Get ¶
Get returns the value of a field in a hash. If the element does not exist, returns ErrNotFound. If the key does not exist or is not a hash, returns ErrNotFound.
func (*DB) GetMany ¶
GetMany returns a map of values for given fields. Ignores fields that do not exist and do not return them in the map. If the key does not exist or is not a hash, returns an empty map.
func (*DB) Incr ¶
Incr increments the integer value of a field in a hash. Returns the value after the increment. If the field does not exist, sets it to 0 before the increment. If the field value is not an integer, returns ErrValueType. If the key does not exist, creates it. If the key exists but is not a hash, returns ErrKeyType.
func (*DB) IncrFloat ¶
IncrFloat increments the float value of a field in a hash. Returns the value after the increment. If the field does not exist, sets it to 0 before the increment. If the field value is not a float, returns ErrValueType. If the key does not exist, creates it. If the key exists but is not a hash, returns ErrKeyType.
func (*DB) Items ¶
Items returns a map of all fields and values in a hash. If the key does not exist or is not a hash, returns an empty map.
func (*DB) Len ¶
Len returns the number of fields in a hash. If the key does not exist or is not a hash, returns 0.
func (*DB) Scan ¶
Scan iterates over hash items with fields matching pattern. Returns a slice of field-value pairs (see HashItem) of size count based on the current state of the cursor. Returns an empty HashItem slice when there are no more items. If the key does not exist or is not a hash, returns a nil slice. Supports glob-style patterns. Set count = 0 for default page size.
func (*DB) Scanner ¶
Scanner returns an iterator for hash items with fields matching pattern. The scanner returns items one by one, fetching them from the database in pageSize batches when necessary. Stops when there are no more items or an error occurs. If the key does not exist or is not a hash, stops immediately. Supports glob-style patterns. Set pageSize = 0 for default page size.
func (*DB) Set ¶
Set creates or updates the value of a field in a hash. Returns true if the field was created, false if it was updated. If the key does not exist, creates it. If the key exists but is not a hash, returns ErrKeyType.
func (*DB) SetMany ¶
SetMany creates or updates the values of multiple fields in a hash. Returns the number of fields created (as opposed to updated). If the key does not exist, creates it. If the key exists but is not a hash, returns ErrKeyType.
func (*DB) SetNotExists ¶
SetNotExists creates the value of a field in a hash if it does not exist. Returns true if the field was created, false if it already exists. If the key does not exist, creates it. If the key exists but is not a hash, returns ErrKeyType.
type ScanResult ¶
ScanResult represents a result of the scan command.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner is the iterator for hash items. Stops when there are no more items or an error occurs.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is a hash repository transaction.
func (*Tx) Delete ¶
Delete deletes one or more items from a hash. Returns the number of fields deleted. Ignores non-existing fields. Does nothing if the key does not exist or is not a hash.
func (*Tx) Exists ¶
Exists checks if a field exists in a hash. If the key does not exist or is not a hash, returns false.
func (*Tx) Fields ¶
Fields returns all fields in a hash. If the key does not exist or is not a hash, returns an empty slice.
func (*Tx) Get ¶
Get returns the value of a field in a hash. If the element does not exist, returns ErrNotFound. If the key does not exist or is not a hash, returns ErrNotFound.
func (*Tx) GetMany ¶
GetMany returns a map of values for given fields. Ignores fields that do not exist and do not return them in the map. If the key does not exist or is not a hash, returns an empty map.
func (*Tx) Incr ¶
Incr increments the integer value of a field in a hash. Returns the value after the increment. If the field does not exist, sets it to 0 before the increment. If the field value is not an integer, returns ErrValueType. If the key does not exist, creates it. If the key exists but is not a hash, returns ErrKeyType.
func (*Tx) IncrFloat ¶
IncrFloat increments the float value of a field in a hash. Returns the value after the increment. If the field does not exist, sets it to 0 before the increment. If the field value is not a float, returns ErrValueType. If the key does not exist, creates it. If the key exists but is not a hash, returns ErrKeyType.
func (*Tx) Items ¶
Items returns a map of all fields and values in a hash. If the key does not exist or is not a hash, returns an empty map.
func (*Tx) Len ¶
Len returns the number of fields in a hash. If the key does not exist or is not a hash, returns 0.
func (*Tx) Scan ¶
Scan iterates over hash items with fields matching pattern. Returns a slice of field-value pairs (see HashItem) of size count based on the current state of the cursor. Returns an empty HashItem slice when there are no more items. If the key does not exist or is not a hash, returns a nil slice. Supports glob-style patterns. Set count = 0 for default page size.
func (*Tx) Scanner ¶
Scanner returns an iterator for hash items with fields matching pattern. The scanner returns items one by one, fetching them from the database in pageSize batches when necessary. Stops when there are no more items or an error occurs. If the key does not exist or is not a hash, stops immediately. Supports glob-style patterns. Set pageSize = 0 for default page size.
func (*Tx) Set ¶
Set creates or updates the value of a field in a hash. Returns true if the field was created, false if it was updated. If the key does not exist, creates it. If the key exists but is not a hash, returns ErrKeyType.
func (*Tx) SetMany ¶
SetMany creates or updates the values of multiple fields in a hash. Returns the number of fields created (as opposed to updated). If the key does not exist, creates it. If the key exists but is not a hash, returns ErrKeyType.
func (*Tx) SetNotExists ¶
SetNotExists creates the value of a field in a hash if it does not exist. Returns true if the field was created, false if it already exists. If the key does not exist, creates it. If the key exists but is not a hash, returns ErrKeyType.