bedis

package module
v0.0.0-...-fc27e5a Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2020 License: MIT Imports: 16 Imported by: 0

README

Bedis

starting a Redis server and using it as the "Builtin Redis"

Usage

package main

import (
    "fmt"

    "github.com/wrfly/bedis"
)

func main() {
    builtin, err := bedis.New(bedis.Option{
        Memory: "3GB",
    })
    if err != nil {
        panic(err)
    }
    defer builtin.StopAndClose()

    client, err := builtin.DefaultClient()
    if err != nil {
        panic(err)
    }

    // set key
    if err := client.Set("key", 12345, -1).Err(); err != nil {
        panic(err)
    }
    // get key
    if v, err := client.Get("key").Result(); err == nil {
        fmt.Println("redis get value", v)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuiltinRedis

type BuiltinRedis interface {
	NewClient(cfg redis.Options) (*redis.Client, error)
	DefaultClient() (*redis.Client, error)
	StopAndClose()
}

BuiltinRedis represents the redis runing on localhost, connected via a socket remember to `StopAndClose` it after the program exit

func New

func New(opt Option) (_ BuiltinRedis, err error)

New will first download the redis and init the config if anything goes wrong at the statup stage, return error however, if the redis-server exit for 3 times, library will panic, means the builtin redis is not avaliable

type Option

type Option struct {
	MuteLog bool

	// Set a memory usage limit to the specified amount of bytes.
	// When the memory limit is reached Redis will try to remove keys
	// according to the eviction policy selected (see maxmemory-policy).
	Memory string `default:"3gb"` // redis max memory

	CPUAffinity bool `yaml:"cpu-affinity"`

	Config map[string]string `yaml:"config"` // other configs, kv pair
}

Option to config the builtin redis

Jump to

Keyboard shortcuts

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