Documentation
¶
Overview ¶
Package rkey is a database-backed key repository. It provides methods to interact with keys in the database.
Index ¶
- type DB
- func (db *DB) Count(keys ...string) (int, error)
- func (db *DB) Delete(keys ...string) (int, error)
- func (db *DB) DeleteAll() error
- func (db *DB) DeleteExpired(n int) (count int, err error)
- func (db *DB) Exists(key string) (bool, error)
- func (db *DB) Expire(key string, ttl time.Duration) error
- func (db *DB) ExpireAt(key string, at time.Time) error
- func (db *DB) Get(key string) (core.Key, error)
- func (db *DB) Keys(pattern string) ([]core.Key, error)
- func (db *DB) Len() (int, error)
- func (db *DB) Persist(key string) error
- func (db *DB) Random() (core.Key, error)
- func (db *DB) Rename(key, newKey string) error
- func (db *DB) RenameNotExists(key, newKey string) (bool, error)
- func (db *DB) Scan(cursor int, pattern string, ktype core.TypeID, count int) (ScanResult, error)
- func (db *DB) Scanner(pattern string, ktype core.TypeID, pageSize int) *Scanner
- type ScanResult
- type Scanner
- type Tx
- func (tx *Tx) Count(keys ...string) (int, error)
- func (tx *Tx) Delete(keys ...string) (int, error)
- func (tx *Tx) DeleteAll() error
- func (tx *Tx) Exists(key string) (bool, error)
- func (tx *Tx) Expire(key string, ttl time.Duration) error
- func (tx *Tx) ExpireAt(key string, at time.Time) error
- func (tx *Tx) Get(key string) (core.Key, error)
- func (tx *Tx) Keys(pattern string) ([]core.Key, error)
- func (tx *Tx) Len() (int, error)
- func (tx *Tx) Persist(key string) error
- func (tx *Tx) Random() (core.Key, error)
- func (tx *Tx) Rename(key, newKey string) error
- func (tx *Tx) RenameNotExists(key, newKey string) (bool, error)
- func (tx *Tx) Scan(cursor int, pattern string, ktype core.TypeID, count int) (ScanResult, error)
- func (tx *Tx) Scanner(pattern string, ktype core.TypeID, pageSize int) *Scanner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB is a database-backed key repository. A key is a unique identifier for a data structure (string, list, hash, etc.). Use the key repository to manage all keys regardless of their type.
func (*DB) Delete ¶
Delete deletes keys and their values, regardless of the type. Returns the number of deleted keys. Non-existing keys are ignored.
func (*DB) DeleteAll ¶
DeleteAll deletes all keys and their values, effectively resetting the database. Should not be run inside a database transaction.
func (*DB) DeleteExpired ¶
DeleteExpired deletes keys with expired TTL, but no more than n keys. If n = 0, deletes all expired keys.
func (*DB) Expire ¶
Expire sets a time-to-live (ttl) for the key using a relative duration. After the ttl passes, the key is expired and no longer exists. If the key does not exist, returns ErrNotFound.
func (*DB) ExpireAt ¶
ExpireAt sets an expiration time for the key. After this time, the key is expired and no longer exists. If the key does not exist, returns ErrNotFound.
func (*DB) Get ¶
Get returns a specific key with all associated details. If the key does not exist, returns ErrNotFound.
func (*DB) Keys ¶
Keys returns all keys matching pattern. Supports glob-style patterns like these:
key* k?y k[bce]y k[!a-c][y-z]
Use this method only if you are sure that the number of keys is limited. Otherwise, use the DB.Scan or DB.Scanner methods.
func (*DB) Persist ¶
Persist removes the expiration time for the key. If the key does not exist, returns ErrNotFound.
func (*DB) Rename ¶
Rename changes the key name. If there is an existing key with the new name, it is replaced. If the old key does not exist, returns ErrNotFound.
func (*DB) RenameNotExists ¶
RenameNotExists changes the key name. If there is an existing key with the new name, does nothing. Returns true if the key was renamed, false otherwise.
func (*DB) Scan ¶
Scan iterates over keys matching pattern. Returns a slice of keys (see core.Key) of size count based on the current state of the cursor. Returns an empty slice when there are no more keys.
Filtering and limiting options:
- pattern (glob-style) to filter keys by name (* = any name).
- ktype to filter keys by type (TypeAny = any type).
- count to limit the number of keys returned (0 = default).
func (*DB) Scanner ¶
Scanner returns an iterator for keys matching pattern. The scanner returns keys one by one, fetching them from the database in pageSize batches when necessary. Stops when there are no more items or an error occurs.
Filtering and pagination options:
- pattern (glob-style) to filter keys by name (* = any name).
- ktype to filter keys by type (TypeAny = any type).
- pageSize to limit the number of keys fetched at once (0 = default).
type ScanResult ¶
ScanResult represents a result of the Scan call.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner is the iterator for keys. Stops when there are no more keys or an error occurs.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is a key repository transaction.
func (*Tx) Delete ¶
Delete deletes keys and their values, regardless of the type. Returns the number of deleted keys. Non-existing keys are ignored.
func (*Tx) DeleteAll ¶
DeleteAll deletes all keys and their values, effectively resetting the database. Should not be run inside a database transaction.
func (*Tx) Expire ¶
Expire sets a time-to-live (ttl) for the key using a relative duration. After the ttl passes, the key is expired and no longer exists. If the key does not exist, returns ErrNotFound.
func (*Tx) ExpireAt ¶
ExpireAt sets an expiration time for the key. After this time, the key is expired and no longer exists. If the key does not exist, returns ErrNotFound.
func (*Tx) Get ¶
Get returns a specific key with all associated details. If the key does not exist, returns ErrNotFound.
func (*Tx) Keys ¶
Keys returns all keys matching pattern. Supports glob-style patterns like these:
key* k?y k[bce]y k[!a-c][y-z]
Use this method only if you are sure that the number of keys is limited. Otherwise, use the Tx.Scan or Tx.Scanner methods.
func (*Tx) Persist ¶
Persist removes the expiration time for the key. If the key does not exist, returns ErrNotFound.
func (*Tx) Rename ¶
Rename changes the key name. If there is an existing key with the new name, it is replaced. If the old key does not exist, returns ErrNotFound.
func (*Tx) RenameNotExists ¶
RenameNotExists changes the key name. If there is an existing key with the new name, does nothing. Returns true if the key was renamed, false otherwise.
func (*Tx) Scan ¶
Scan iterates over keys matching pattern. Returns a slice of keys (see core.Key) of size count based on the current state of the cursor. Returns an empty slice when there are no more keys.
Filtering and limiting options:
- pattern (glob-style) to filter keys by name (* = any name).
- ktype to filter keys by type (TypeAny = any type).
- count to limit the number of keys returned (0 = default).
func (*Tx) Scanner ¶
Scanner returns an iterator for keys matching pattern. The scanner returns keys one by one, fetching them from the database in pageSize batches when necessary. Stops when there are no more items or an error occurs.
Filtering and pagination options:
- pattern (glob-style) to filter keys by name (* = any name).
- ktype to filter keys by type (TypeAny = any type).
- pageSize to limit the number of keys fetched at once (0 = default).