Documentation
¶
Overview ¶
Package rstring is a database-backed string repository. It provides methods to interact with strings in the database.
Index ¶
- type DB
- func (d *DB) Get(key string) (core.Value, error)
- func (d *DB) GetMany(keys ...string) (map[string]core.Value, error)
- func (d *DB) Incr(key string, delta int) (int, error)
- func (d *DB) IncrFloat(key string, delta float64) (float64, error)
- func (d *DB) Set(key string, value any) error
- func (d *DB) SetExpires(key string, value any, ttl time.Duration) error
- func (d *DB) SetMany(items map[string]any) error
- func (d *DB) SetWith(key string, value any) SetCmd
- type SetCmd
- type SetOut
- type Tx
- func (tx *Tx) Get(key string) (core.Value, error)
- func (tx *Tx) GetMany(keys ...string) (map[string]core.Value, error)
- func (tx *Tx) Incr(key string, delta int) (int, error)
- func (tx *Tx) IncrFloat(key string, delta float64) (float64, error)
- func (tx *Tx) Set(key string, value any) error
- func (tx *Tx) SetExpires(key string, value any, ttl time.Duration) error
- func (tx *Tx) SetMany(items map[string]any) error
- func (tx *Tx) SetWith(key string, value any) SetCmd
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB is a database-backed string repository. A string is a slice of bytes associated with a key. Use the string repository to work with individual strings.
func (*DB) Get ¶
Get returns the value of the key. If the key does not exist or is not a string, returns ErrNotFound.
func (*DB) GetMany ¶
GetMany returns a map of values for given keys. Ignores keys that do not exist or not strings, and does not return them in the map.
func (*DB) Incr ¶
Incr increments the integer key value by the specified amount. Returns the value after the increment. If the key does not exist, sets it to 0 before the increment. If the key value is not an integer, returns ErrValueType. If the key exists but is not a string, returns ErrKeyType.
func (*DB) IncrFloat ¶
IncrFloat increments the float key value by the specified amount. Returns the value after the increment. If the key does not exist, sets it to 0 before the increment. If the key value is not an float, returns ErrValueType. If the key exists but is not a string, returns ErrKeyType.
func (*DB) Set ¶
Set sets the key value that will not expire. Overwrites the value if the key already exists. If the key exists but is not a string, returns ErrKeyType.
func (*DB) SetExpires ¶
SetExpires sets the key value with an optional expiration time (if ttl > 0). Overwrites the value and ttl if the key already exists. If the key exists but is not a string, returns ErrKeyType.
type SetCmd ¶ added in v0.3.0
type SetCmd struct {
// contains filtered or unexported fields
}
SetCmd sets the key value.
func (SetCmd) IfExists ¶ added in v0.3.0
IfExists instructs to set the value only if the key exists.
func (SetCmd) IfNotExists ¶ added in v0.3.0
IfNotExists instructs to set the value only if the key does not exist.
func (SetCmd) KeepTTL ¶ added in v0.3.0
KeepTTL instructs to keep the expiration time already set for the key.
func (SetCmd) Run ¶ added in v0.3.0
Run sets the key value according to the configured options. Returns the previous value (if any) and the operation result (if the key was created or updated).
Expiration time handling:
- If called with TTL() > 0 or At(), sets the expiration time.
- If called with KeepTTL(), keeps the expiration time already set for the key.
- If called without TTL(), At() or KeepTTL(), sets the value that will not expire.
Existence checks:
- If called with IfExists(), sets the value only if the key exists.
- If called with IfNotExists(), sets the value only if the key does not exist.
If the key exists but is not a string, returns ErrKeyType (unless called with IfExists(), in which case does nothing).
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is a string repository transaction.
func (*Tx) Get ¶
Get returns the value of the key. If the key does not exist or is not a string, returns ErrNotFound.
func (*Tx) GetMany ¶
GetMany returns a map of values for given keys. Ignores keys that do not exist or not strings, and does not return them in the map.
func (*Tx) Incr ¶
Incr increments the integer key value by the specified amount. Returns the value after the increment. If the key does not exist, sets it to 0 before the increment. If the key value is not an integer, returns ErrValueType. If the key exists but is not a string, returns ErrKeyType.
func (*Tx) IncrFloat ¶
IncrFloat increments the float key value by the specified amount. Returns the value after the increment. If the key does not exist, sets it to 0 before the increment. If the key value is not an float, returns ErrValueType. If the key exists but is not a string, returns ErrKeyType.
func (*Tx) Set ¶
Set sets the key value that will not expire. Overwrites the value if the key already exists. If the key exists but is not a string, returns ErrKeyType.
func (*Tx) SetExpires ¶
SetExpires sets the key value with an optional expiration time (if ttl > 0). Overwrites the value and ttl if the key already exists. If the key exists but is not a string, returns ErrKeyType.