cache

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a struct that represents a Redis cache. It contains a prefix that is prepended to all keys in the cache, and a client that is used to interact with the Redis server.

func NewCache

func NewCache(options *redis.Options, prefix string) (*Cache, error)

NewCache is a function that creates a new Cache. It takes a pointer to a redis.Options struct, which contains options for the Redis client, and a prefix string, which is prepended to all keys in the cache. It returns a pointer to the created Cache and an error.

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, request *DeleteRequest) (int64, error)

Delete is a method of Cache that deletes a key from the cache. It takes a context and a pointer to a DeleteRequest struct, and returns the number of keys that were deleted as an int64 and an error. The method uses the Redis DEL command to delete the key.

func (*Cache) Exists

func (c *Cache) Exists(ctx context.Context, request *ExistsRequest) (bool, error)

Exists is a method of Cache that checks if a key exists in the cache. It takes a context and a pointer to an ExistsRequest struct, and returns a boolean indicating whether the key exists and an error. The method uses the Redis EXISTS command to check if the key exists.

func (*Cache) Expire

func (c *Cache) Expire(ctx context.Context, request *ExpireRequest) (bool, error)

Expire is a method of Cache that sets the expiration time of a key in the cache. It takes a context and a pointer to an ExpireRequest struct, and returns a boolean indicating whether the expiration time was set and an error. The method uses the Redis EXPIRE command to set the expiration time.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, request *GetCacheRequest) (string, error)

Get is a method of Cache that gets a value from the cache. It takes a context and a pointer to a GetCacheRequest struct, and returns the value as a string and an error. The method uses the Redis GET command to get the value.

func (*Cache) GetListIndex

func (c *Cache) GetListIndex(ctx context.Context, request *GetListIndexRequest) (int, error)

GetListIndex is a method of Cache that gets the index of a value in a list in the cache. It takes a context and a pointer to a GetListIndexRequest struct, and returns the index of the value as an int and an error. The method uses the Redis LRANGE command to get the list, and then iterates over the list to find the value.

func (*Cache) Inc

func (c *Cache) Inc(ctx context.Context, request *IncRequest) (int64, error)

Inc is a method of Cache that increments a value in the cache. It takes a context and a pointer to an IncRequest struct, and returns the new value as an int64 and an error. The method uses the Redis INCR command to increment the value.

func (*Cache) IncrBy

func (c *Cache) IncrBy(ctx context.Context, request *IncrByRequest) (int64, error)

IncrBy is a method of Cache that increments a value in the cache by a certain amount. It takes a context and a pointer to an IncrByRequest struct, and returns the new value as an int64 and an error. The method uses the Redis INCRBY command to increment the value.

func (*Cache) LPop

func (c *Cache) LPop(ctx context.Context, request *LPopRequest) (string, error)

LPop is a method of Cache that pops a value from a list in the cache. It takes a context and a pointer to a LPopRequest struct, and returns the popped value as a string and an error. The method uses the Redis LPOP command to pop the value.

func (*Cache) LPush

func (c *Cache) LPush(ctx context.Context, request *LPushRequest) (int64, error)

LPush is a method of Cache that pushes a value onto a list in the cache. It takes a context and a pointer to a LPushRequest struct, and returns the length of the list after the push as an int64 and an error. The method uses the Redis LPUSH command to push the value.

func (*Cache) LRange added in v0.0.19

func (c *Cache) LRange(ctx context.Context, request *LRangeRequest) ([]string, error)

LRange is a method of Cache that gets a range of values from a list in the cache. It takes a context and a pointer to a LRangeRequest struct, and returns the values as a slice of strings and an error. The method uses the Redis LRANGE command to get the values.

func (*Cache) LRem added in v0.0.21

func (c *Cache) LRem(ctx context.Context, request *LRemRequest) (int64, error)

LRem is a method of Cache that removes occurrences of a value from a list in the cache. It takes a context and a pointer to a LRemRequest struct, and returns the number of occurrences that were removed and an error. The method uses the Redis LREM command to remove the occurrences.

func (*Cache) LRemBeforeKey added in v0.0.27

func (c *Cache) LRemBeforeKey(ctx context.Context, request *LRemByValueRequest) error

LRemBeforeKey is a method of Cache that removes all elements in a list before a specified value. It takes a context and a pointer to a LRemByValueRequest struct, and returns an error if any occurs during the operation.

The method uses the Redis LRANGE command to get all elements in the list, then iterates over the list to find the specified value. If the value is found at the start of the list, all elements are removed using the Redis DEL command. If the value is found elsewhere in the list, all elements before it are removed using the Redis LTRIM command.

func (*Cache) RPop

func (c *Cache) RPop(ctx context.Context, request *RPopRequest) (string, error)

RPop is a method of Cache that pops a value from the end of a list in the cache. It takes a context and a pointer to a RPopRequest struct, and returns the popped value as a string and an error. The method uses the Redis RPOP command to pop the value.

func (*Cache) SAdd added in v0.0.16

func (c *Cache) SAdd(ctx context.Context, request *SAddRequest) (int64, error)

SAdd is a method of Cache that adds members to a set in the cache. It takes a context and a pointer to a SAddRequest struct, and returns the number of members that were added and an error. The method uses the Redis SADD command to add the members.

func (*Cache) SCard added in v0.0.16

func (c *Cache) SCard(ctx context.Context, request *SCardRequest) (int64, error)

SCard is a method of Cache that gets the number of members in a set in the cache. It takes a context and a pointer to a SCardRequest struct, and returns the number of members as an int64 and an error. The method uses the Redis SCARD command to get the number of members.

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, request *SetCacheRequest) error

Set is a method of Cache that sets a value in the cache. It takes a context and a pointer to a SetCacheRequest struct, and returns an error. The method uses the Redis SET command to set the value.

func (*Cache) SetNX added in v0.0.21

func (c *Cache) SetNX(ctx context.Context, request *SetNXRequest) (bool, error)

SetNX is a method of Cache that sets a key in the cache, only if the key does not exist. It takes a context and a pointer to a SetNXRequest struct, and returns a boolean indicating whether the key was set and an error. The method uses the Redis SETNX command to set the key.

func (*Cache) TTL

func (c *Cache) TTL(ctx context.Context, request *TTLRequest) (time.Duration, error)

TTL is a method of Cache that gets the time to live of a key in the cache. It takes a context and a pointer to a TTLRequest struct, and returns the time to live as a time.Duration and an error. The method uses the Redis TTL command to get the time to live.

func (*Cache) ZAdd

func (c *Cache) ZAdd(ctx context.Context, request *ZAddRequest) (int64, error)

ZAdd is a method of Cache that adds members to a sorted set in the cache. It takes a context and a pointer to a ZAddRequest struct, and returns the number of members that were added and an error. The method uses the Redis ZADD command to add the members.

func (*Cache) ZCard

func (c *Cache) ZCard(ctx context.Context, request *ZCardRequest) (int64, error)

ZCard is a method of Cache that gets the number of members in a sorted set in the cache. It takes a context and a pointer to a ZCardRequest struct, and returns the number of members as an int64 and an error. The method uses the Redis ZCARD command to get the number of members.

func (*Cache) ZRange

func (c *Cache) ZRange(ctx context.Context, request *ZRangeRequest) ([]string, error)

ZRange is a method of Cache that gets a range of members from a sorted set in the cache. It takes a context and a pointer to a ZRangeRequest struct, and returns the members as a slice of strings and an error. The method uses the Redis ZRANGE command to get the members.

func (*Cache) ZRank

func (c *Cache) ZRank(ctx context.Context, request *ZRankRequest) (int64, error)

ZRank is a method of Cache that gets the rank of a member in a sorted set in the cache. It takes a context and a pointer to a ZRankRequest struct, and returns the rank of the member as an int64 and an error. The method uses the Redis ZRANK command to get the rank.

func (*Cache) ZRem

func (c *Cache) ZRem(ctx context.Context, request *ZRemRequest) (int64, error)

ZRem is a method of Cache that removes members from a sorted set in the cache. It takes a context and a pointer to a ZRemRequest struct, and returns the number of members that were removed and an error. The method uses the Redis ZREM command to remove the members.

func (*Cache) ZScan

func (c *Cache) ZScan(ctx context.Context, request *ZScanRequest) ([]string, uint64, error)

ZScan is a method of Cache that incrementally iterates over a sorted set in the cache. It takes a context and a pointer to a ZScanRequest struct, and returns the members as a slice of strings, the next cursor, and an error. The method uses the Redis ZSCAN command to iterate over the members.

type DeleteRequest added in v0.0.9

type DeleteRequest struct {
	Key    string
	Prefix *string
}

DeleteRequest is a struct that represents a request to delete a key from the cache. It contains the key to delete and an optional custom prefix.

type ExistsRequest added in v0.0.9

type ExistsRequest struct {
	Key    string
	Prefix *string
}

ExistsRequest is a struct that represents a request to check if a key exists in the cache. It contains the key and an optional custom prefix.

type ExpireRequest added in v0.0.9

type ExpireRequest struct {
	Key     string
	Seconds int64
	Prefix  *string
}

ExpireRequest is a struct that represents a request to set the expiration time of a key in the cache. It contains the key, the expiration time in seconds, and an optional custom prefix.

type GetCacheRequest added in v0.0.9

type GetCacheRequest struct {
	Key    string
	Prefix *string
}

GetCacheRequest is a struct that represents a request to get a value from the cache. It contains the key to get and an optional custom prefix.

type GetListIndexRequest added in v0.0.9

type GetListIndexRequest struct {
	Key    string
	Value  string
	Prefix *string
}

GetListIndexRequest is a struct that represents a request to get the index of a value in a list in the cache. It contains the key of the list, the value to find, and an optional custom prefix.

type IncRequest added in v0.0.9

type IncRequest struct {
	Key    string
	Prefix *string
}

IncRequest is a struct that represents a request to increment a value in the cache. It contains the key to increment and an optional custom prefix.

type IncrByRequest added in v0.0.9

type IncrByRequest struct {
	Key    string
	Value  int64
	Prefix *string
}

IncrByRequest is a struct that represents a request to increment a value in the cache by a certain amount. It contains the key to increment, the amount to increment by, and an optional custom prefix.

type LPopRequest added in v0.0.9

type LPopRequest struct {
	Key    string
	Prefix *string
}

LPopRequest is a struct that represents a request to pop a value from a list in the cache. It contains the key of the list and an optional custom prefix.

type LPushRequest added in v0.0.9

type LPushRequest struct {
	Key    string
	Value  []interface{}
	Prefix *string
}

LPushRequest is a struct that represents a request to push a value onto a list in the cache. It contains the key of the list, the value to push, and an optional custom prefix.

type LRangeRequest added in v0.0.19

type LRangeRequest struct {
	Key    string
	Value  string
	Prefix *string
}

LRangeRequest is a struct that represents a request to get a range of values from a list in the cache. It contains the key of the list, the range to get, and an optional custom prefix.

type LRemByValueRequest added in v0.0.27

type LRemByValueRequest struct {
	Key    string
	Value  string
	Prefix *string
}

type LRemRequest added in v0.0.21

type LRemRequest struct {
	Key    string
	Count  int64
	Value  interface{}
	Prefix *string
}

LRemRequest is a struct that represents a request to remove occurrences of a value from a list in the cache. It contains the key of the list, the count of occurrences to remove, the value to remove, and an optional custom prefix.

type RPopRequest added in v0.0.9

type RPopRequest struct {
	Key    string
	Prefix *string
}

RPopRequest is a struct that represents a request to pop a value from the end of a list in the cache. It contains the key of the list and an optional custom prefix.

type SAddRequest added in v0.0.16

type SAddRequest struct {
	Key    string
	Value  []interface{}
	Prefix *string
}

SAddRequest is a struct that represents a request to add members to a set in the cache. It contains the key of the set, the members to add, and an optional custom prefix.

type SCardRequest added in v0.0.16

type SCardRequest struct {
	Key    string
	Prefix *string
}

SCardRequest is a struct that represents a request to get the number of members in a set in the cache. It contains the key of the set and an optional custom prefix.

type SetCacheRequest added in v0.0.9

type SetCacheRequest struct {
	Key     string
	Value   []byte
	Seconds int64
	Prefix  *string
}

SetCacheRequest is a struct that represents a request to set a value in the cache. It contains the key to set, the value to set it to, the expiration time in seconds, and an optional custom prefix.

type SetNXRequest added in v0.0.21

type SetNXRequest struct {
	Key     string
	Value   interface{}
	Seconds int64
	Prefix  *string
}

SetNXRequest is a struct that represents a request to set a key in the cache, only if the key does not exist. It contains the key, the value to set, the expiration time in seconds, and an optional custom prefix.

type TTLRequest added in v0.0.9

type TTLRequest struct {
	Key    string
	Prefix *string
}

TTLRequest is a struct that represents a request to get the time to live of a key in the cache. It contains the key and an optional custom prefix.

type ZAddRequest added in v0.0.9

type ZAddRequest struct {
	Key     string
	Members []redis.Z
	Prefix  *string
}

ZAddRequest is a struct that represents a request to add members to a sorted set in the cache. It contains the key of the sorted set, the members to add, and an optional custom prefix.

type ZCardRequest added in v0.0.9

type ZCardRequest struct {
	Key    string
	Prefix *string
}

ZCardRequest is a struct that represents a request to get the number of members in a sorted set in the cache. It contains the key of the sorted set and an optional custom prefix.

type ZRangeRequest added in v0.0.9

type ZRangeRequest struct {
	Key    string
	Start  int64
	End    int64
	Prefix *string
}

ZRangeRequest is a struct that represents a request to get a range of members from a sorted set in the cache. It contains the key of the sorted set, the start and end of the range, and an optional custom prefix.

type ZRankRequest added in v0.0.9

type ZRankRequest struct {
	Key    string
	Member string
	Prefix *string
}

ZRankRequest is a struct that represents a request to get the rank of a member in a sorted set in the cache. It contains the key of the sorted set, the member to find, and an optional custom prefix.

type ZRemRequest added in v0.0.9

type ZRemRequest struct {
	Key     string
	Members []interface{}
	Prefix  *string
}

ZRemRequest is a struct that represents a request to remove members from a sorted set in the cache. It contains the key of the sorted set, the members to remove, and an optional custom prefix.

type ZScanRequest added in v0.0.9

type ZScanRequest struct {
	Key    string
	Cursor uint64
	Match  string
	Count  int64
	Prefix *string
}

ZScanRequest is a struct that represents a request to incrementally iterate over a sorted set in the cache. It contains the key of the sorted set, a cursor to resume the iteration, a match pattern to filter the members, a count to limit the number of returned members per call, and an optional custom prefix.

Jump to

Keyboard shortcuts

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