redis

package
v0.0.0-...-dbfa1ae Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: MPL-2.0 Imports: 13 Imported by: 0

README

This repo creates a redis-cluster of master-slave replicas using the cloud-cluster framework. It will create one master instance and two replicas.

Install redis

$ apt-get install

This commands installs 'redis-server' (0.4) and 'redis-cli'. Besides, it starts redis on the background as a systemctl script. To stop it, run:

$ sudo systemctl disable redis-server

Note that the version of redis installed is not the last stable one. However, it suffices to perform the cluster tests.

Usage

Deploy a consul agent in dev mode:

consul agent -dev

Deploy three servers:

$ go run main.go agent --node one --bootstrap-expect 3 --serf-port 8001 --rpc-port 5001 --http-port 4001 --backend redis --field=port=6001 --dev

$ go run main.go agent --node two --bootstrap-expect 3 --serf-port 8002 --rpc-port 5002 --http-port 4002 --backend redis --field=port=6002 --dev

$ go run main.go agent --node three --bootstrap-expect 3 --serf-port 8003 --rpc-port 5003 --http-port 4003 --backend redis --field=port=6003 --dev

Once all the nodes are active, you can run:

$ redis-cli -p 6001

to access the instance at port 6001. Then, you can run:

$ redis-cli -p 6001 set "a" 1

to change the value of "a" to 1 or:

$ redis-cli -p 6001 set "a" 2

to retrieve the value of "a".

In a redis cluster, read queries (get) can be done to any machine from the cluster. However, insert queries (set) can only be performed on master. If you try to set a value on any of the replicas you will get this message:

$ redis-cli -p <port> set "a" 2
(error) READONLY You can't write against a read only slave. 

Internals

Right now, there is no way for the nodes in the raft cluster to know when there is a new master and if they are the secondary instances. Only the master receives those notifications. In this cluster, once the master is selected, it will send a "Status.SlaveOf" message to each slave node so that they can sync with the master.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedisBackend

func NewRedisBackend(logger hclog.Logger) backend.Backend

NewRedisBackend creates a new redis backend

Types

type Config

type Config struct {
	// Port is the port for the redis server
	Port int `mapstructure:"port"`
}

Config is the configuration for the redis backend

type Redis

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

Redis is a redis backend

func (*Redis) Close

func (r *Redis) Close() error

Close implements the backend interface

func (*Redis) EmitStats

func (r *Redis) EmitStats(period time.Duration, stopCh <-chan struct{})

EmitStats implements the backend interface

func (*Redis) Ports

func (r *Redis) Ports() int

Ports implements the backend interface

func (*Redis) SetConfig

func (r *Redis) SetConfig(config map[string]interface{}) error

SetConfig implements the backend interface

func (*Redis) Setup

func (r *Redis) Setup(view *backend.Config) error

Setup starts the backend process

type SlaveOfRequest

type SlaveOfRequest struct {
	Addr string
	Port int
}

SlaveOfRequest is the request for the slaveOf method

type Stats

type Stats struct {
	Slaves            int     `mapstructure:"connected_slaves"`
	UsedMemory        int64   `mapstructure:"used_memory"`
	UsedMemoryDataset int64   `mapstructure:"used_memory_dataset"`
	UsedCPUSys        float64 `mapstructure:"used_cpu_sys"`
}

Stats are the stats for the redis client

type System

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

System is the system endpoint for redis

func (*System) SlaveOf

func (s *System) SlaveOf(args SlaveOfRequest, reply *bool) error

SlaveOf sets the instance as secondary

Jump to

Keyboard shortcuts

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