Documentation ¶
Overview ¶
Package rset is a database-backed set repository. It provides methods to interact with sets in the database.
Index ¶
- type DB
- func (d *DB) Add(key string, elems ...any) (int, error)
- func (d *DB) Delete(key string, elems ...any) (int, error)
- func (d *DB) Diff(keys ...string) ([]core.Value, error)
- func (d *DB) DiffStore(dest string, keys ...string) (int, error)
- func (d *DB) Exists(key, elem any) (bool, error)
- func (d *DB) Inter(keys ...string) ([]core.Value, error)
- func (d *DB) InterStore(dest string, keys ...string) (int, error)
- func (d *DB) Items(key string) ([]core.Value, error)
- func (d *DB) Len(key string) (int, error)
- func (d *DB) Move(src, dest string, elem any) error
- func (d *DB) Pop(key string) (core.Value, error)
- func (d *DB) Random(key string) (core.Value, 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) Union(keys ...string) ([]core.Value, error)
- func (d *DB) UnionStore(dest string, keys ...string) (int, error)
- type ScanResult
- type Scanner
- type Tx
- func (tx *Tx) Add(key string, elems ...any) (int, error)
- func (tx *Tx) Delete(key string, elems ...any) (int, error)
- func (tx *Tx) Diff(keys ...string) ([]core.Value, error)
- func (tx *Tx) DiffStore(dest string, keys ...string) (int, error)
- func (tx *Tx) Exists(key, elem any) (bool, error)
- func (tx *Tx) Inter(keys ...string) ([]core.Value, error)
- func (tx *Tx) InterStore(dest string, keys ...string) (int, error)
- func (tx *Tx) Items(key string) ([]core.Value, error)
- func (tx *Tx) Len(key string) (int, error)
- func (tx *Tx) Move(src, dest string, elem any) error
- func (tx *Tx) Pop(key string) (core.Value, error)
- func (tx *Tx) Random(key string) (core.Value, 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) Union(keys ...string) ([]core.Value, error)
- func (tx *Tx) UnionStore(dest string, keys ...string) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB is a database-backed set repository. A set is an unordered collection of unique strings. Use the set repository to work with individual sets and their elements, and to perform set operations.
func (*DB) Add ¶
Add adds or updates elements in a set. Returns the number of elements created (as opposed to updated). If the key does not exist, creates it. If the key exists but is not a set, returns ErrKeyType.
func (*DB) Delete ¶
Delete removes elements from a set. Returns the number of elements removed. Ignores the elements that do not exist. Does nothing if the key does not exist or is not a set.
func (*DB) Diff ¶
Diff returns the difference between the first set and the rest. The difference consists of elements that are present in the first set but not in any of the rest. If the first key does not exist or is not a set, returns an empty slice. If any of the remaining keys do not exist or are not sets, ignores them.
func (*DB) DiffStore ¶
DiffStore calculates the difference between the first source set and the rest, and stores the result in a destination set. Returns the number of elements in the destination set. If the destination key already exists, it is fully overwritten (all old elements are removed and the new ones are inserted). If the destination key already exists and is not a set, returns ErrKeyType. If the first source key does not exist or is not a set, does nothing, except deleting the destination key if it exists. If any of the remaining source keys do not exist or are not sets, ignores them.
func (*DB) Exists ¶
Exists reports whether the element belongs to a set. If the key does not exist or is not a set, returns false.
func (*DB) Inter ¶
Inter returns the intersection of multiple sets. The intersection consists of elements that exist in all given sets. If any of the source keys do not exist or are not sets, returns an empty slice.
func (*DB) InterStore ¶
InterStore intersects multiple sets and stores the result in a destination set. Returns the number of elements in the destination set. If the destination key already exists, it is fully overwritten (all old elements are removed and the new ones are inserted). If the destination key already exists and is not a set, returns ErrKeyType. If any of the source keys do not exist or are not sets, does nothing, except deleting the destination key if it exists.
func (*DB) Items ¶
Items returns all elements in a set. If the key does not exist or is not a set, returns an empty slice.
func (*DB) Len ¶
Len returns the number of elements in a set. Returns 0 if the key does not exist or is not a set.
func (*DB) Move ¶
Move moves an element from one set to another. If the element does not exist in the source set, returns ErrNotFound. If the source key does not exist or is not a set, returns ErrNotFound. If the destination key does not exist, creates it. If the destination key exists but is not a set, returns ErrKeyType. If the element already exists in the destination set, only deletes it from the source set.
func (*DB) Pop ¶
Pop removes and returns a random element from a set. If the key does not exist or is not a set, returns ErrNotFound.
func (*DB) Random ¶
Random returns a random element from a set. If the key does not exist or is not a set, returns ErrNotFound.
func (*DB) Scan ¶
Scan iterates over set elements matching pattern. Returns a slice of elements of size count based on the current state of the cursor. Returns an empty slice when there are no more items. If the key does not exist or is not a set, returns an empty slice. Supports glob-style patterns. Set count = 0 for default page size.
func (*DB) Scanner ¶
Scanner returns an iterator over set elements 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 set, stops immediately. Supports glob-style patterns. Set pageSize = 0 for default page size.
func (*DB) Union ¶
Union returns the union of multiple sets. The union consists of elements that exist in any of the given sets. Ignores the keys that do not exist or are not sets. If no keys exist, returns an empty slice.
func (*DB) UnionStore ¶
UnionStore unions multiple sets and stores the result in a destination set. Returns the number of elements in the destination set. If the destination key already exists, it is fully overwritten (all old elements are removed and the new ones are inserted). If the destination key already exists and is not a set, returns ErrKeyType. Ignores the source keys that do not exist or are not sets. If all of the source keys do not exist or are not sets, does nothing, except deleting the destination key if it exists.
type ScanResult ¶
ScanResult is a result of the scan operation.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner is the iterator for set 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 set repository transaction.
func (*Tx) Add ¶
Add adds or updates elements in a set. Returns the number of elements created (as opposed to updated). If the key does not exist, creates it. If the key exists but is not a set, returns ErrKeyType.
func (*Tx) Delete ¶
Delete removes elements from a set. Returns the number of elements removed. Ignores the elements that do not exist. Does nothing if the key does not exist or is not a set.
func (*Tx) Diff ¶
Diff returns the difference between the first set and the rest. The difference consists of elements that are present in the first set but not in any of the rest. If the first key does not exist or is not a set, returns an empty slice. If any of the remaining keys do not exist or are not sets, ignores them.
func (*Tx) DiffStore ¶
DiffStore calculates the difference between the first source set and the rest, and stores the result in a destination set. Returns the number of elements in the destination set. If the destination key already exists, it is fully overwritten (all old elements are removed and the new ones are inserted). If the destination key already exists and is not a set, returns ErrKeyType. If the first source key does not exist or is not a set, does nothing, except deleting the destination key if it exists. If any of the remaining source keys do not exist or are not sets, ignores them.
func (*Tx) Exists ¶
Exists reports whether the element belongs to a set. If the key does not exist or is not a set, returns false.
func (*Tx) Inter ¶
Inter returns the intersection of multiple sets. The intersection consists of elements that exist in all given sets. If any of the source keys do not exist or are not sets, returns an empty slice.
func (*Tx) InterStore ¶
InterStore intersects multiple sets and stores the result in a destination set. Returns the number of elements in the destination set. If the destination key already exists, it is fully overwritten (all old elements are removed and the new ones are inserted). If the destination key already exists and is not a set, returns ErrKeyType. If any of the source keys do not exist or are not sets, does nothing, except deleting the destination key if it exists.
func (*Tx) Items ¶
Items returns all elements in a set. If the key does not exist or is not a set, returns an empty slice.
func (*Tx) Len ¶
Len returns the number of elements in a set. Returns 0 if the key does not exist or is not a set.
func (*Tx) Move ¶
Move moves an element from one set to another. If the element does not exist in the source set, returns ErrNotFound. If the source key does not exist or is not a set, returns ErrNotFound. If the destination key does not exist, creates it. If the destination key exists but is not a set, returns ErrKeyType. If the element already exists in the destination set, only deletes it from the source set.
func (*Tx) Pop ¶
Pop removes and returns a random element from a set. If the key does not exist or is not a set, returns ErrNotFound.
func (*Tx) Random ¶
Random returns a random element from a set. If the key does not exist or is not a set, returns ErrNotFound.
func (*Tx) Scan ¶
Scan iterates over set elements matching pattern. Returns a slice of elements of size count based on the current state of the cursor. Returns an empty slice when there are no more items. If the key does not exist or is not a set, returns an empty slice. Supports glob-style patterns. Set count = 0 for default page size.
func (*Tx) Scanner ¶
Scanner returns an iterator over set elements 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 set, stops immediately. Supports glob-style patterns. Set pageSize = 0 for default page size.
func (*Tx) Union ¶
Union returns the union of multiple sets. The union consists of elements that exist in any of the given sets. Ignores the keys that do not exist or are not sets. If no keys exist, returns an empty slice.
func (*Tx) UnionStore ¶
UnionStore unions multiple sets and stores the result in a destination set. Returns the number of elements in the destination set. If the destination key already exists, it is fully overwritten (all old elements are removed and the new ones are inserted). If the destination key already exists and is not a set, returns ErrKeyType. Ignores the source keys that do not exist or are not sets. If all of the source keys do not exist or are not sets, does nothing, except deleting the destination key if it exists.