databases

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Databases = services.DatabaseDefinitions{
	"redis": services.DatabaseDefinition{
		Name:              "Redis Database",
		Description:       "For Production Use",
		Maker:             MakeRedisAsDatabase,
		SettingsValidator: ValidateRedisSettings,
	},
	"redis-shard": services.DatabaseDefinition{
		Name:              "Redis Sharded Database",
		Description:       "For Production Use",
		Maker:             MakeRedisShardAsDatabase,
		SettingsValidator: ValidateRedisShardSettings,
	},
	"in-memory": services.DatabaseDefinition{
		Name:              "In-memory Database (no persistence! just use for testing)",
		Description:       "An in-memory database for testing only",
		Maker:             MakeInMemory,
		SettingsValidator: ValidateInMemorySettings,
	},
}
View Source
var NotFound = fmt.Errorf("not found")
View Source
var RedisForm = forms.Form{
	ErrorMsg: "invalid data encountered in the Redis config form",
	Fields: []forms.Field{
		{
			Name: "addresses",
			Validators: []forms.Validator{
				forms.IsOptional{Default: []string{}},
				forms.IsStringList{},
			},
		},
		{
			Name: "sentinel_addresses",
			Validators: []forms.Validator{
				forms.IsOptional{Default: []string{}},
				forms.IsStringList{},
			},
		},
		{
			Name: "master_name",
			Validators: []forms.Validator{
				forms.IsOptional{Default: ""},
				forms.IsString{},
			},
		},
		{
			Name: "database",
			Validators: []forms.Validator{
				forms.IsOptional{Default: 0},
				forms.IsInteger{Min: 0, Max: 100},
			},
		},
		{
			Name: "password",
			Validators: []forms.Validator{
				forms.IsRequired{},
				forms.IsString{},
			},
		},
		{
			Name: "sentinel_username",
			Validators: []forms.Validator{
				forms.IsOptional{},
				forms.IsString{},
			},
		},
		{
			Name: "sentinel_password",
			Validators: []forms.Validator{
				forms.IsOptional{},
				forms.IsString{},
			},
		},
		{
			Name: "shard_index",
			Validators: []forms.Validator{
				forms.IsOptional{Default: 0},
				forms.IsInteger{},
			},
		},
	},
}
View Source
var RedisShardForm = forms.Form{
	ErrorMsg: "invalid data encountered in the Redis config form",
	Fields: []forms.Field{
		{
			Name: "shards",
			Validators: []forms.Validator{
				forms.IsList{
					Validators: []forms.Validator{
						forms.IsStringMap{Form: &RedisForm},
					},
				},
			},
		},
	},
}

Functions

func MakeInMemory

func MakeInMemory(settings interface{}) (services.Database, error)

func MakeRedisAsDatabase

func MakeRedisAsDatabase(settings interface{}) (services.Database, error)

func MakeRedisClient

func MakeRedisClient(settings interface{}) (redis.UniversalClient, uint32, error)

func MakeRedisShardAsDatabase

func MakeRedisShardAsDatabase(settings interface{}) (services.Database, error)

func ValidateInMemorySettings

func ValidateInMemorySettings(settings map[string]interface{}) (interface{}, error)

func ValidateRedisSettings

func ValidateRedisSettings(settings map[string]interface{}) (interface{}, error)

func ValidateRedisShardSettings

func ValidateRedisShardSettings(settings map[string]interface{}) (interface{}, error)

Types

type InMemory

type InMemory struct {
	Data map[string][][]byte
	TTLs []*TTL
}

func (*InMemory) Close

func (d *InMemory) Close() error

func (*InMemory) Expire

func (d *InMemory) Expire(table string, key []byte, ttl time.Duration) error

func (*InMemory) ExpireAt

func (d *InMemory) ExpireAt(table string, key []byte, tm time.Time) error

func (*InMemory) Integer

func (d *InMemory) Integer(table string, key []byte) services.Integer

func (*InMemory) List

func (d *InMemory) List(table string, key []byte) services.List

func (*InMemory) Lock

func (d *InMemory) Lock(lockKey string, a, b time.Duration) (services.Lock, error)

func (*InMemory) LockDefault

func (d *InMemory) LockDefault(key string) (services.Lock, error)

func (*InMemory) Map

func (d *InMemory) Map(table string, key []byte) services.Map

func (*InMemory) Open

func (d *InMemory) Open() error

func (*InMemory) Reset

func (d *InMemory) Reset() error

func (*InMemory) Set

func (d *InMemory) Set(table string, key []byte) services.Set

func (*InMemory) SortedSet

func (d *InMemory) SortedSet(table string, key []byte) services.SortedSet

func (*InMemory) Value

func (d *InMemory) Value(table string, key []byte) services.Value

type InMemorySettings

type InMemorySettings struct {
}

type MetricHook

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

func (MetricHook) AfterProcess

func (m MetricHook) AfterProcess(ctx context.Context, cmd redis.Cmder) error

func (MetricHook) AfterProcessPipeline

func (m MetricHook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error

func (MetricHook) BeforeProcess

func (m MetricHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error)

func (MetricHook) BeforeProcessPipeline

func (m MetricHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error)

type Redis

type Redis struct {
	Ctx context.Context
	// contains filtered or unexported fields
}

func MakeRedis

func MakeRedis(settings interface{}) (*Redis, error)

func MakeRedisShards

func MakeRedisShards(settings interface{}) (*Redis, error)

func (*Redis) Client

func (d *Redis) Client(key string) redis.UniversalClient

func (*Redis) Close

func (d *Redis) Close() error

func (*Redis) Expire

func (d *Redis) Expire(table string, key []byte, ttl time.Duration) error

func (*Redis) ExpireAt

func (d *Redis) ExpireAt(table string, key []byte, tm time.Time) error

func (*Redis) Integer

func (d *Redis) Integer(table string, key []byte) services.Integer

func (*Redis) List

func (d *Redis) List(table string, key []byte) services.List

func (*Redis) Lock

func (d *Redis) Lock(
	lockKey string,
	lockWait time.Duration,
	ttl time.Duration,
) (services.Lock, error)

func (*Redis) LockDefault

func (d *Redis) LockDefault(key string) (services.Lock, error)

func (*Redis) Map

func (d *Redis) Map(table string, key []byte) services.Map

func (*Redis) Open

func (d *Redis) Open() error

func (*Redis) Reset

func (d *Redis) Reset() error

func (*Redis) Set

func (d *Redis) Set(table string, key []byte) services.Set

func (*Redis) SortedSet

func (d *Redis) SortedSet(table string, key []byte) services.SortedSet

func (*Redis) Value

func (d *Redis) Value(table string, key []byte) services.Value

type RedisInteger

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

func (*RedisInteger) DecrBy

func (r *RedisInteger) DecrBy(value int64) (int64, error)

func (*RedisInteger) Del

func (r *RedisInteger) Del() error

func (*RedisInteger) Get

func (r *RedisInteger) Get() (int64, error)

func (*RedisInteger) IncrBy

func (r *RedisInteger) IncrBy(value int64) (int64, error)

func (*RedisInteger) Set

func (r *RedisInteger) Set(value int64, ttl time.Duration) error

type RedisLock

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

func (*RedisLock) Release

func (r *RedisLock) Release() error

type RedisMap

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

func (*RedisMap) Del

func (r *RedisMap) Del(key []byte) error

func (*RedisMap) Get

func (r *RedisMap) Get(key []byte) ([]byte, error)

func (*RedisMap) GetAll

func (r *RedisMap) GetAll() (map[string][]byte, error)

func (*RedisMap) Set

func (r *RedisMap) Set(key []byte, value []byte) error

type RedisSet

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

func (*RedisSet) Add

func (r *RedisSet) Add(data []byte) error

func (*RedisSet) Del

func (r *RedisSet) Del(data []byte) error

func (*RedisSet) Has

func (r *RedisSet) Has(data []byte) (bool, error)

func (*RedisSet) Members

func (r *RedisSet) Members() ([]*services.SetEntry, error)

type RedisSettings

type RedisSettings struct {
	MasterName        string   `json:"master_name"`
	Addresses         []string `json:"addresses`
	SentinelAddresses []string `json:"sentinel_addresses`
	Database          int64    `json:"database"`
	Password          string   `json:"password"`
	SentinelUsername  string   `json:"sentinel_username"`
	SentinelPassword  string   `json:"sentinel_password"`
	ShardIndex        int64    `json:"shard_index"`
}

type RedisShardSettings

type RedisShardSettings struct {
	Shards []RedisSettings `json:"shards"`
}

type RedisSortedSet

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

func (*RedisSortedSet) Add

func (r *RedisSortedSet) Add(data []byte, score int64) error

func (*RedisSortedSet) At

func (r *RedisSortedSet) At(index int64) (*services.SortedSetEntry, error)

func (*RedisSortedSet) Del

func (r *RedisSortedSet) Del(data []byte) (bool, error)

func (*RedisSortedSet) PopMin

func (r *RedisSortedSet) PopMin(n int64) ([]*services.SortedSetEntry, error)

func (*RedisSortedSet) Range

func (r *RedisSortedSet) Range(from, to int64) ([]*services.SortedSetEntry, error)

func (*RedisSortedSet) RangeByScore

func (r *RedisSortedSet) RangeByScore(from, to int64) ([]*services.SortedSetEntry, error)

func (*RedisSortedSet) RemoveRangeByScore

func (r *RedisSortedSet) RemoveRangeByScore(from, to int64) error

func (*RedisSortedSet) Score

func (r *RedisSortedSet) Score(data []byte) (int64, error)

type RedisValue

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

func (*RedisValue) Del

func (r *RedisValue) Del() error

func (*RedisValue) Get

func (r *RedisValue) Get() ([]byte, error)

func (*RedisValue) Set

func (r *RedisValue) Set(data []byte, ttl time.Duration) error

type TTL

type TTL struct {
	Key string
	TTL time.Time
}

Jump to

Keyboard shortcuts

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