去redis池

  • U2_374547
    了解作者
  • 28.7KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-05 11:04
    上传日期
去redis池 go-redis-pool旨在在Redis主从模式下实现读/写拆分,以及分片数据的简便方法。 安装 go-redis-pool需要具有支持的Go版本,并使用导入版本控制。 因此,请确保在安装go-redis-pool之前初始化Go模块: go mod init github.com/my/repo go get github.com/bitleak/go-redis-pool 快速开始 可通过获得API文档和示例 设置主从池 pool , err := pool . NewHA ( & pool. HAConfig { Master : "127.0.0.1:6379" , Slaves : [] string { "127.0.0.1:6380" , "127.0.0.1:6381" ,
go-redis-pool-master.zip
  • go-redis-pool-master
  • .gitignore
    316B
  • go.mod
    165B
  • pool_test.go
    49.5KB
  • Makefile
    863B
  • util_test.go
    567B
  • .travis.yml
    736B
  • hashkit
  • fnv.go
    131B
  • ketama_test.go
    1.5KB
  • ketama.go
    2.7KB
  • hashkit.go
    169B
  • md5.go
    131B
  • main_test.go
    190B
  • LICENSE
    1KB
  • go.sum
    4.3KB
  • hooks.go
    1016B
  • examples
  • sharding.go
    715B
  • ha.go
    654B
  • ha_conn_factory_test.go
    2.8KB
  • scripts
  • redis
  • docker-compose.yml
    535B
  • README.md
    4.4KB
  • util.go
    270B
  • .coveralls.yml
    52B
  • shard_conn_factory.go
    4.2KB
  • ha_conn_factory.go
    8.1KB
  • pool.go
    45.6KB
  • Changelog
    44B
内容介绍
# go-redis-pool [![Build Status](https://travis-ci.org/bitleak/go-redis-pool.svg?branch=master)](https://travis-ci.org/bitleak/go-redis-pool) [![Go Report Card](https://goreportcard.com/badge/github.com/bitleak/go-redis-pool)](https://goreportcard.com/report/github.com/bitleak/go-redis-pool) [![Coverage Status](https://coveralls.io/repos/github/bitleak/go-redis-pool/badge.svg?branch=master)](https://coveralls.io/github/bitleak/go-redis-pool?branch=master) [![GitHub release](https://img.shields.io/github/tag/bitleak/go-redis-pool.svg?label=release)](https://github.com/bitleak/go-redis-pool/releases) [![GitHub release date](https://img.shields.io/github/release-date/bitleak/go-redis-pool.svg)](https://github.com/bitleak/go-redis-pool/releases) [![LICENSE](https://img.shields.io/github/license/bitleak/go-redis-pool.svg)](https://github.com/bitleak/go-redis-pool/blob/master/LICENSE) [![GoDoc](https://img.shields.io/badge/Godoc-reference-blue.svg)](https://godoc.org/github.com/bitleak/go-redis-pool) go-redis-pool was designed to implement the read/write split in Redis master-slave mode, and easy way to sharding the data. ## Installation go-redis-pool requires a Go version with [Modules](https://github.com/golang/go/wiki/Modules) support and uses import versioning. So please make sure to initialize a Go module before installing go-redis-pool: ```shell go mod init github.com/my/repo go get github.com/bitleak/go-redis-pool ``` ## Quick Start API documentation and examples are available via [godoc](https://godoc.org/github.com/bitleak/go-redis-pool) ### Setup The Master-Slave Pool ```go pool, err := pool.NewHA(&pool.HAConfig{ Master: "127.0.0.1:6379", Slaves: []string{ "127.0.0.1:6380", "127.0.0.1:6381", }, Password: "", // set master password ReadonlyPassword: "", // use password if no set }) pool.Set("foo", "bar", 0) ``` The read-only commands would go throught slaves and write commands would into the master instance. We use the Round-Robin as default when determing which slave to serve the readonly request, and currently supports: * RoundRobin (default) * Random * Weight For example, we change the distribution type to `Weight`: ```go pool, err := pool.NewHA(&pool.HAConfig{ Master: "127.0.0.1:6379", Slaves: []string{ "127.0.0.1:6380", // default weight is 100 if missing "127.0.0.1:6381:200", // weight is 200 "127.0.0.1:6382:300", // weigght is 300 }, PollType: pool.PollByWeight, }) ``` The first slave would serve 1/6 reqeusts, and second slave would serve 2/6, last one would serve 3/6. ##### Auto Eject The Failure Host ``` pool, err := pool.NewHA(&pool.HAConfig{ Master: "127.0.0.1:6379", Slaves: []string{ "127.0.0.1:6380", // default weight is 100 if missing "127.0.0.1:6381:200", // weight is 200 "127.0.0.1:6382:300", // weigght is 300 }, AutoEjectHost: true, ServerFailureLimit: 3, ServerRetryTimeout: 5 * time.Second, MinServerNum: 2, }) ``` The pool would evict the host if reached `ServerFailureLimit` times of failure and retry the host after `ServerRetryTimeout`. The `MinServerNum` was used to avoid evicting too many and would overrun other alive servers. #### Setup The Sharding Pool ```go pool, err := pool.NewShard(&pool.ShardConfig{ Shards: []*HAConfig { // shard 1 &pool.HAConfig{ Master: "127.0.0.1:6379", Slaves: []string{ "127.0.0.1:6380", "127.0.0.1:6381", }, Password: "", // set master password ReadonlyPassword: "", // use password if no set }, // shard 2 &pool.HAConfig{ Master: "127.0.0.1:6382", Slaves: []string{ "127.0.0.1:6383", }, Password: "", // set master password ReadonlyPassword: "", // use password if no set }, }, }) pool.Set("foo", "bar", 0) ``` Shard pool use the `CRC32` as default hash function when sharding the key, you can overwrite the `HashFn` in config if wants to use other sharding hash function. The distribution type supports `ketama` and `modular`, default is modular. ## Test ```shell $ make test ``` ## See Also [https://github.com/go-redis/redis](https://github.com/go-redis/redis)
评论
    相关推荐
    • redis-github-action:在 GitHub 操作中使用 Redis
      GitHub 中的 Redis 操作 在您的 GitHub 操作中启动 Redis 服务器。 关注和以获取更新! 介绍 此 GitHub 操作在默认端口6379上启动 Redis 服务器。 这在针对 Redis 数据库运行测试时很有用。 用法 一个代码示例说 ...
    • redis安装包
      先获取redis源码包 ,tar zxvf redis-stable.tar.gz cd redis-stable make make install 最好再编译后直接执行make install命令来将这些可执行程序复制到/user/local/bin目录中以便以后执行程序时可以不用输入完整的...
    • redis安装包
      GitHub被墙,发一个方便大家,这个资源分必须选啊,然而还没有0分的选项,差评了哦!~。~|||
    • redis4.0.8
      redis-4.0.8安装包,文档中有安装过程和注意事项、安装教程。
    • redis4.0.10
      redis作为缓存是当前互联网项目用的最多的,需要的同学自行下载
    • redis-developer.github.io
      网站 该网站是使用 (现代的静态网站生成器)构建的。 安装 yarn install 当地发展 yarn start 此命令将启动本地开发服务器并... 如果您使用GitHub页面进行托管,则此命令是构建网站并推送至gh-pages分支的便捷方法。
    • redis github搬运工
      github 搬运过来的适用于windows 的redis,顺便混点积分,哈
    • redis_client
      在pub中查看它: : 和GitHub: : 用法 import 'package:redis_client/redis_client.dart' ; void main () async { final client = await RedisClient . connect ( 'localhost' ); await client. set ( 'name' , ...
    • Redis 安装包
      Linux redis 4.0 源码编译完成 可直接使用 ./redis-cli /redis.conf window 3.0 免安装版 附:redis 桌面管理工具
    • SIM800C_MQTT.rar
      使用SIM800C模块,使用MQTT协议,连接中国移动onenet平台,能实现数据的订阅、发布、存储等