Documentation ¶
Index ¶
- func NewRedisDatastore(name string, conn txn.Connector) txn.Datastorer
- type ConnectionOptions
- type RedisConnection
- func (r *RedisConnection) ConditionalUpdate(key string, value txn.DataItem, doCreate bool) error
- func (r *RedisConnection) Connect() error
- func (r *RedisConnection) Delete(name string) error
- func (r *RedisConnection) Get(name string) (string, error)
- func (r *RedisConnection) GetItem(key string) (txn.DataItem, error)
- func (r *RedisConnection) Put(name string, value any) error
- func (r *RedisConnection) PutItem(key string, value txn.DataItem) error
- type RedisConnectionInterface
- type RedisDatastore
- type RedisItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRedisDatastore ¶
func NewRedisDatastore(name string, conn txn.Connector) txn.Datastorer
NewRedisDatastore creates a new instance of RedisDatastore with the given name and Redis connection.
Types ¶
type ConnectionOptions ¶
type RedisConnection ¶
type RedisConnection struct { Address string // contains filtered or unexported fields }
func NewRedisConnection ¶
func NewRedisConnection(config *ConnectionOptions) *RedisConnection
NewRedisConnection creates a new Redis connection using the provided configuration options. If the config parameter is nil, default values will be used. The Redis connection is established using the specified address and password. The address format should be in the form "host:port". The se parameter is used for data serialization and deserialization. If se is nil, a default JSON serializer will be used. Returns a pointer to the created RedisConnection.
func (*RedisConnection) ConditionalUpdate ¶
ConditionalUpdate updates the value of a Redis item if the version matches the provided value. It takes a key string and a txn.DataItem value as parameters. If the item's version does not match, it returns a version mismatch error. Otherwise, it updates the item with the provided values and returns the updated item.
func (*RedisConnection) Connect ¶
func (r *RedisConnection) Connect() error
Connect establishes a connection to the Redis server. It returns an error if the connection cannot be established.
func (*RedisConnection) Delete ¶
func (r *RedisConnection) Delete(name string) error
Delete removes the specified key from Redis. It allows for the deletion of a key that does not exist.
func (*RedisConnection) Get ¶
func (r *RedisConnection) Get(name string) (string, error)
Get retrieves the value associated with the given key from the Redis database. If the key is not found, it returns an empty string and an error indicating the key was not found. If an error occurs during the retrieval, it returns an empty string and the error. Otherwise, it returns the retrieved value and nil error.
func (*RedisConnection) GetItem ¶
func (r *RedisConnection) GetItem(key string) (txn.DataItem, error)
GetItem retrieves a txn.DataItem from the Redis database based on the specified key. If the key is not found, it returns an empty txn.DataItem and an error.
func (*RedisConnection) Put ¶
func (r *RedisConnection) Put(name string, value any) error
Put stores the given value with the specified name in the Redis database. It will overwrite the value if the key already exists. It returns an error if the operation fails.
func (*RedisConnection) PutItem ¶
func (r *RedisConnection) PutItem(key string, value txn.DataItem) error
PutItem puts an item into the Redis database with the specified key and value. It sets various fields of the txn.DataItem struct as hash fields in the Redis hash. The function returns an error if there was a problem executing the Redis commands.
type RedisConnectionInterface ¶
type RedisConnectionInterface interface { Connect() error GetItem(key string) (RedisItem, error) PutItem(key string, value RedisItem) error ConditionalUpdate(key string, value RedisItem, doCreate bool) error Get(name string) (string, error) Put(name string, value any) error Delete(name string) error }
type RedisDatastore ¶
RedisDatastore represents a datastore implementation using Redis as the underlying storage.
type RedisItem ¶
type RedisItem struct { Key string `redis:"Key"` Value string `redis:"Value"` TxnId string `redis:"TxnId"` TxnState config.State `redis:"TxnState"` TValid time.Time `redis:"TValid"` TLease time.Time `redis:"TLease"` Prev string `redis:"Prev"` LinkedLen int `redis:"LinkedLen"` IsDeleted bool `redis:"IsDeleted"` Version int `redis:"Version"` }