<h1 align="center">
<br>Reborn<br>
</h1>
<p align="center"><em>A redis-based configuration library developed using Go, ready to go, easy to use.</em></p>
<p align="center">
<a href="https://github.com/jwma/reborn/workflows/Go/badge.svg?branch=master" target="_blank">
<img src="https://github.com/jwma/reborn/workflows/Go/badge.svg?branch=master" alt="ci">
</a>
<a href="https://img.shields.io/github/license/mashape/apistatus.svg" target="_blank">
<img src="https://img.shields.io/github/license/mashape/apistatus.svg" alt="license">
</a>
</p>
---
[中文](README.zh_cn.md "中文") | [English](README.md "English")
* [Install](#install)
* [Quick Start](#quick-start)
* [More usage](#more-usage)
* [Create a Reborn instance without default configs](#create-a-reborn-instance-without-default-configs)
* [Save multiple Key-Value at one time](#save-multiple-key-value-at-one-time)
* [Start auto reload](#start-auto-reload)
* [Supported types](#supported-types)
* [How to support the other types?](#how-to-support-the-other-types)
* [Notice](#notice)
---
## Install
```console
go get github.com/jwma/reborn
```
## Quick Start
```go
package main
import (
"fmt"
"github.com/go-redis/redis"
"github.com/jwma/reborn"
"log"
)
func main() {
// get your redis client here
client := redis.NewClient(&redis.Options{
Addr: "127.0.0.1:6379",
Password: "",
DB: 0,
IdleTimeout: -1,
})
var err error
// new empty config
defaults := reborn.NewConfig()
// set default config
err = defaults.SetValue("websiteTitle", "Reborn")
if err != nil {
log.Printf("failed to set websiteTitle, error: %v\n", err)
}
err = defaults.SetValue("toggle", false)
if err != nil {
log.Printf("failed to set toggle, error: %v\n", err)
}
// create a Reborn instance using defaults config
// this instance will store all the configs into YOUR_CONFIG_KEY Hash in Redis
r, err := reborn.NewWithDefaults(client, "YOUR_CONFIG_KEY", defaults)
// by passing the second parameter,
// you can get this default value when the key does not exists
websiteTitle := r.GetValue("websiteTitle", "default value")
fmt.Println(websiteTitle) // Output: Reborn
fmt.Println(r.GetValue("noExistsKey", "oops")) // Output: oops
toggle := r.GetBoolValue("toggle", false)
fmt.Println(toggle)
}
```
## More usage
You can use Reborn like below.
### Create a Reborn instance without default configs
```go
r, _ := reborn.New(client, "YOUR_CONFIG_KEY")
```
### Save multiple Key-Value at one time
```go
r, _ := reborn.New(client, "YOUR_CONFIG_KEY")
// SetValue() only update the Reborn instance configs
r.SetValue("discount", 8.8)
r.SetValue("websiteTitle", "Promotion")
// after SetValue(), you can call Persist() save you Key-Value into Redis.
r.Persist()
```
### Start auto reload
After start auto reload function, Reborn will periodically use the database configs to override the config
items of the Reborn instance. However, when the data of the Reborn instance changes, the auto reload function will
skip the override operation and enter the next round of waiting until you call `Persist ()`,
the auto reload will continue the work of reload config items.
```go
r, _ := reborn.New(client, "YOUR_CONFIG_KEY")
r.SetAutoReloadDuration(time.Second * 10) // default duration: 5s
r.StartAutoReload()
// stop auto reload
r.StopAutoReload()
```
## Supported types
The types you can pass when you call `SetValue()`:
- `int`
- `float64`
- `string`
- `bool`
- `[]int`
- `[]string`
- `map[string]int`
- `map[string]string`
_⚠️ You will get the `UnsupportedValueTypeError` when you pass unsupported types._
Call the below functions to get different types value:
- `GetValue()` return `string`
- `GetIntValue()` return `int`
- `GetFloat64Value()` return `float64`
- `GetBoolValue()` return `bool`
- `GetIntSliceValue()` return `[]int`
- `GetStringSliceValue()` return `[]string`
- `GetStringIntMapValue()` return `map[string]int`
- `GetStringStringMapValue()` return `map[string]string`
### How to support the other types?
You can parse the variable to `string`, then you can call `SetValue()`. When you want to get this config item,
you can call `GetValue()` to get `string` types variable, then you parse it back.
Not cool, but it works~
## Notice
**⚠️ DON'T FORGET CALL THE `Persist()`**
After `SetValue()`, don't forget call `Persist()`, if not:
1. Config items will not save into Redis.
2. Auto reload function will not update the config items.
没有合适的资源?快使用搜索试试~ 我知道了~
Reborn 是使用 Go 开发的,基于 Redis 存储的配置库,简单配置,易于使用
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共13个文件
go:4个
md:2个
yml:2个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 5 0 下载量 29 浏览量
2024-05-23
15:53:47
上传
评论
收藏 10KB ZIP 举报
温馨提示
Go语言(也称为Golang)是由Google开发的一种静态强类型、编译型的编程语言。它旨在成为一门简单、高效、安全和并发的编程语言,特别适用于构建高性能的服务器和分布式系统。以下是Go语言的一些主要特点和优势: 简洁性:Go语言的语法简单直观,易于学习和使用。它避免了复杂的语法特性,如继承、重载等,转而采用组合和接口来实现代码的复用和扩展。 高性能:Go语言具有出色的性能,可以媲美C和C++。它使用静态类型系统和编译型语言的优势,能够生成高效的机器码。 并发性:Go语言内置了对并发的支持,通过轻量级的goroutine和channel机制,可以轻松实现并发编程。这使得Go语言在构建高性能的服务器和分布式系统时具有天然的优势。 安全性:Go语言具有强大的类型系统和内存管理机制,能够减少运行时错误和内存泄漏等问题。它还支持编译时检查,可以在编译阶段就发现潜在的问题。 标准库:Go语言的标准库非常丰富,包含了大量的实用功能和工具,如网络编程、文件操作、加密解密等。这使得开发者可以更加专注于业务逻辑的实现,而无需花费太多时间在底层功能的实现上。 跨平台:Go语言支持多种操作系统和平台,包括Windows、Linux、macOS等。它使用统一的构建系统(如Go Modules),可以轻松地跨平台编译和运行代码。 开源和社区支持:Go语言是开源的,具有庞大的社区支持和丰富的资源。开发者可以通过社区获取帮助、分享经验和学习资料。 总之,Go语言是一种简单、高效、安全、并发的编程语言,特别适用于构建高性能的服务器和分布式系统。如果你正在寻找一种易于学习和使用的编程语言,并且需要处理大量的并发请求和数据,那么Go语言可能是一个不错的选择。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![apk](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 13 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/d7864c98224046ec9a7f43fa6207c84e_qq_51320133.jpg!1)
生瓜蛋子
- 粉丝: 3829
- 资源: 5775
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- 数据库管理工具:dbeaver-ce-23.2.1-macos-aarch64.dmg
- 数据库管理工具:dbeaver-ce-23.2.0-stable.x86-64.rpm
- 全国大学生建模大赛题目.pdf
- 数据库管理工具:dbeaver-ce-23.2.0-macos-x86-64.dmg
- 数据库管理工具:dbeaver-ce-23.2.0-macos-aarch64.dmg
- 电机学运动控制课程基础知识-绪论部分
- Delphi 12 控件之HGetIt.zip
- 数据库管理工具:dbeaver-ce-23.1.5-x86-64-setup.exe
- ADS1256的stm32参考程序
- 数据库管理工具:dbeaver-ce-23.1.5-macos-x86-64.dmg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)