storage

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2017 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package storage contains helper functions & structs for high-level work with Redis

Index

Constants

View Source
const (
	START = "0"
	SCAN  = "SCAN"
	SSCAN = "SSCAN"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	KeyTTL    interface{} // Common key time-to-live, if set affects every key used in storage
	Namespace string
	// contains filtered or unexported fields
}

func New

func New(config Configuration) *Client

New creates new Redis client

func (*Client) AddToSet

func (storage *Client) AddToSet(key string, values ...[]byte) error

AddToSet see SADD

func (*Client) Cardinality

func (storage *Client) Cardinality(key string) (int, error)

Cardinality see SCARD

func (*Client) Delete

func (storage *Client) Delete(keys ...string) (int, error)

Delete see DEL

func (*Client) Expire

func (storage *Client) Expire(key string, ttl interface{}) error

Expire see EXPIRE

func (*Client) FieldExist

func (storage *Client) FieldExist(key, field string) (bool, error)

FieldExist see HEXISTS

func (*Client) Get

func (storage *Client) Get(key string) ([]byte, error)

Get see GET

func (*Client) GetAllFromSet

func (storage *Client) GetAllFromSet(key string) ([][]byte, error)

GetAllFromSet see SMEMBERS

func (*Client) GetField

func (storage *Client) GetField(key, field string) ([]byte, error)

GetField see HGET

func (*Client) GetFields

func (storage *Client) GetFields(keyAndFields ...string) (map[string][]byte, error)

GetFields see HMGET

func (*Client) GetValues

func (storage *Client) GetValues(key string) ([][]byte, error)

GetValues see HVALS

func (*Client) Increment

func (storage *Client) Increment(key string, delta int) (int, error)

Increment see INCREMENT

func (*Client) IncrementField

func (storage *Client) IncrementField(key, field string, delta int) (int, error)

IncrementField see HINCRBY

func (*Client) IsMemberOfSet

func (storage *Client) IsMemberOfSet(key string, value []byte) (bool, error)

IsMemberOfSet see SISMEMBER

func (*Client) Keys

func (storage *Client) Keys(template string) ([]string, error)

Keys see SCAN, it does not use KEYS because it recommended by Redis team https://redis.io/commands/keys

func (*Client) MultiGet

func (storage *Client) MultiGet(keys ...string) ([][]byte, error)

MultiGet see MGET

func (*Client) Publish

func (storage *Client) Publish(key string, value []byte) error

Publish see PUBLISH

func (*Client) RemoveFields

func (storage *Client) RemoveFields(keyAndFields ...string) error

RemoveFields see HDEL

func (*Client) RemoveFromSet

func (storage *Client) RemoveFromSet(key string, values ...[]byte) error

RemoveFromSet see SREM

func (*Client) Set

func (storage *Client) Set(key string, value []byte) error

Set see SET

func (*Client) SetField

func (storage *Client) SetField(key, field string, value []byte) error

SetField see HSET

func (*Client) SetFields

func (storage *Client) SetFields(key string, hash map[string]interface{}) error

SetFields see HMSET

func (*Client) StoreUnionSet

func (storage *Client) StoreUnionSet(key string, keys ...string) (int, error)

StoreUnionSet see SUNIONSTORE

type Configuration

type Configuration struct {
	KeyTTL    interface{} // Common key time-to-live, if set affects every key used in storage
	Namespace string

	Pool       *redis.Pool
	Connection redis.Conn
}

func ENV

func ENV(prefix string) Configuration

ENV returns storage configuration from env variables

type Iterator

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

func NewIterator

func NewIterator(options ...Option) *Iterator

func (*Iterator) All

func (iterator *Iterator) All(yield func([]interface{})) error

All iterates all keys with provided function

func (*Iterator) Next

func (iterator *Iterator) Next() ([]interface{}, error)

type Option

type Option func(*Iterator)

func ForSet

func ForSet(key string) Option

func WithBatchSize

func WithBatchSize(batchSize int) Option

func WithCursor

func WithCursor(cursor string) Option

func WithStorage

func WithStorage(storage *Client) Option

func WithTemplate

func WithTemplate(template string) Option

type Setter

type Setter struct {
	Storage *Client
	TTL     interface{}
	Key     string
	Value   []byte
}

func (Setter) Call

func (setter Setter) Call() error

func (Setter) Set

func (setter Setter) Set(ttl int) error

type TTL

type TTL struct {
	Key   string
	Value interface{}
}

func (TTL) Seconds

func (ttl TTL) Seconds() int

Seconds returns converted time from initial value in seconds

Jump to

Keyboard shortcuts

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