Documentation ¶
Index ¶
- Constants
- func NewRedisDatastore(name string, conn txn.Connector) txn.Datastorer
- type ConnectionOptions
- type RedisConnection
- func (r *RedisConnection) AtomicCreate(name string, value any) (string, error)
- func (r *RedisConnection) ConditionalCommit(key string, version string) (string, error)
- func (r *RedisConnection) ConditionalUpdate(key string, value txn.DataItem, doCreate bool) (string, 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) (string, error)
- type RedisConnectionInterface
- type RedisDatastore
- type RedisItem
- func (r *RedisItem) Empty() bool
- func (r *RedisItem) Equal(other txn.DataItem) bool
- func (r *RedisItem) IsDeleted() bool
- func (r *RedisItem) Key() string
- func (r *RedisItem) LinkedLen() int
- func (r RedisItem) MarshalBinary() (data []byte, err error)
- func (r *RedisItem) Prev() string
- func (r *RedisItem) SetIsDeleted(d bool)
- func (r *RedisItem) SetLinkedLen(l int)
- func (r *RedisItem) SetPrev(p string)
- func (r *RedisItem) SetTLease(t time.Time)
- func (r *RedisItem) SetTValid(t time.Time)
- func (r *RedisItem) SetTxnState(s config.State)
- func (r *RedisItem) SetValue(v string)
- func (r *RedisItem) SetVersion(v string)
- func (r RedisItem) String() string
- func (r *RedisItem) TLease() time.Time
- func (r *RedisItem) TValid() time.Time
- func (r *RedisItem) TxnId() string
- func (r *RedisItem) TxnState() config.State
- func (r *RedisItem) Value() string
- func (r *RedisItem) Version() string
- type RedisItemFactory
Constants ¶
const AtomicCreateItemScript = `` /* 622-byte string literal not displayed */
const AtomicCreateScript = `` /* 141-byte string literal not displayed */
const ConditionalCommitScript = `` /* 252-byte string literal not displayed */
const ConditionalUpdateScript = `` /* 637-byte string literal not displayed */
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) AtomicCreate ¶
func (r *RedisConnection) AtomicCreate(name string, value any) (string, error)
func (*RedisConnection) ConditionalCommit ¶
func (r *RedisConnection) ConditionalCommit(key string, version string) (string, error)
ConditionalCommit updates the txnState and version of a Redis item if the version matches the provided value. It takes a key string and a version string 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) ConditionalUpdate ¶
func (r *RedisConnection) ConditionalUpdate(key string, value txn.DataItem, doCreate bool) (string, error)
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.
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 { RKey string `redis:"Key" json:"Key"` RValue string `redis:"Value" json:"Value"` RTxnId string `redis:"TxnId" json:"TxnId"` RTxnState config.State `redis:"TxnState" json:"TxnState"` RTValid time.Time `redis:"TValid" json:"TValid"` RTLease time.Time `redis:"TLease" json:"TLease"` RPrev string `redis:"Prev" json:"Prev"` RLinkedLen int `redis:"LinkedLen" json:"LinkedLen"` RIsDeleted bool `redis:"IsDeleted" json:"IsDeleted"` RVersion string `redis:"Version" json:"Version"` }
func NewRedisItem ¶
func NewRedisItem(options txn.ItemOptions) *RedisItem
func (RedisItem) MarshalBinary ¶
func (*RedisItem) SetIsDeleted ¶
func (*RedisItem) SetLinkedLen ¶
func (*RedisItem) SetTxnState ¶
func (*RedisItem) SetVersion ¶
type RedisItemFactory ¶
type RedisItemFactory struct{}
func (*RedisItemFactory) NewDataItem ¶
func (r *RedisItemFactory) NewDataItem(options txn.ItemOptions) txn.DataItem