Giter Club home page Giter Club logo

redigo-codis's Introduction

Redigo Codis

Redigo Codis is a go client for codis based on Redigo.

Features

  • Use a round robin policy to balance load to multiple codis proxies.
  • Detect proxy online and offline automatically.

How to use

import (
    "time"

    "github.com/garyburd/redigo/redis"
    "github.com/tranch-xiao/redigo-codis"
)

p := &codis.Pool{
    ZkServers: []string{"locallhost:8021"},
    ZkTimeout: time.Second * 60,
    ZkPath: "/codis/proxy",
    Dail: func(network, address string) (redis.Conn, error) {
        conn, err := redis.Dial(network, address)
        if err == nil {
            conn.Send("AUTH", "PASSWORD")
        }
        return conn, err
    },
}

r := p.Get()
r.Do("SET", "key", "value")

redigo-codis's People

Contributors

tranch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

redigo-codis's Issues

初始化连接池遇到了问题

下面是我初始化的代码(没有密码):

func init() {
	client = &codis.Pool{
		ZkServers: []string{"10.100.55.51:2181"},
		ZkTimeout: time.Second * 60,
		ZkDir: "/zk/codis/db_lzh_test/proxy",
		Dial: func(network, address string) (redis.Conn, error) {
			conn, err := redis.Dial(network, address)
			
			return conn, err
		},
	}
}

发现连接池连接数是0,查看源码发现在 codis.go 的 52 行,转化session的时候, data 中没有 Proto_typeProxy_addr。data的值为:

{
   "id":"proxy_10.100.55.51_10190",
   "addr":"10.100.55.51:10190",
   "last_event":"",
   "last_event_ts":0,
   "state":"online",
   "description":"",
   "debug_var_addr":"10.100.55.51:10191",
   "pid":19,
   "start_at":"2017-09-07 02:02:31.613248063 +0000 UTC"
}

链接codis的样例代码更新

p := &codis.Pool{
	ZkServers: []string{"locallhost:8021"},
	ZkTimeout: time.Second * 60,
	ZkDir: "/codis/proxy",
	Dial: func(network, address string) (redis.Conn, error) {
		conn, err := redis.Dial(network, address)
		if err == nil {
			conn.Send("AUTH", "PASSWORD")
		}
		return conn, err
	},
}

连接关闭问题

时间久了,发现pool 中的链接closed了,出现了error,不能正常使用。源码中没有做链接有效性的验证,并且一个zk 只创建了一个链接。

我修改了Dial 函数 返回一个*redis.Pool ,实现方式是用的redisgo。并修改了Get 方法,先得到一个zk的redis.Pool,再用redisgo中的Get方法得到链接。发现没有出现链接无效的问题。有个遗憾就是没有把所有zk的链接放在一个pool中。不知道大神有什么其他好的方法,望相告

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.