redis

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const AtomicCreateItemScript = `` /* 622-byte string literal not displayed */
View Source
const AtomicCreateScript = `` /* 141-byte string literal not displayed */
View Source
const ConditionalCommitScript = `` /* 252-byte string literal not displayed */
View Source
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 ConnectionOptions struct {
	Address  string
	Password string

	PoolSize int
	// contains filtered or unexported fields
}

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.

func (*RedisConnection) PutItem

func (r *RedisConnection) PutItem(key string, value txn.DataItem) (string, 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

type RedisDatastore struct {
	*txn.Datastore
}

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) Empty

func (r *RedisItem) Empty() bool

func (*RedisItem) Equal

func (r *RedisItem) Equal(other txn.DataItem) bool

func (*RedisItem) IsDeleted

func (r *RedisItem) IsDeleted() bool

func (*RedisItem) Key

func (r *RedisItem) Key() string

func (*RedisItem) LinkedLen

func (r *RedisItem) LinkedLen() int

func (RedisItem) MarshalBinary

func (r RedisItem) MarshalBinary() (data []byte, err error)

func (*RedisItem) Prev

func (r *RedisItem) Prev() string

func (*RedisItem) SetIsDeleted

func (r *RedisItem) SetIsDeleted(d bool)

func (*RedisItem) SetLinkedLen

func (r *RedisItem) SetLinkedLen(l int)

func (*RedisItem) SetPrev

func (r *RedisItem) SetPrev(p string)

func (*RedisItem) SetTLease

func (r *RedisItem) SetTLease(t time.Time)

func (*RedisItem) SetTValid

func (r *RedisItem) SetTValid(t time.Time)

func (*RedisItem) SetTxnState

func (r *RedisItem) SetTxnState(s config.State)

func (*RedisItem) SetValue

func (r *RedisItem) SetValue(v string)

func (*RedisItem) SetVersion

func (r *RedisItem) SetVersion(v string)

func (RedisItem) String

func (r RedisItem) String() string

func (*RedisItem) TLease

func (r *RedisItem) TLease() time.Time

func (*RedisItem) TValid

func (r *RedisItem) TValid() time.Time

func (*RedisItem) TxnId

func (r *RedisItem) TxnId() string

func (*RedisItem) TxnState

func (r *RedisItem) TxnState() config.State

func (*RedisItem) Value

func (r *RedisItem) Value() string

func (*RedisItem) Version

func (r *RedisItem) Version() string

type RedisItemFactory

type RedisItemFactory struct{}

func (*RedisItemFactory) NewDataItem

func (r *RedisItemFactory) NewDataItem(options txn.ItemOptions) txn.DataItem

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL