Documentation ¶
Overview ¶
@author zhangxiaomin
@author zxm @date 2020-09-08 @description 一致性hash的实现算法,参考自https://blog.csdn.net/xcl168/article/details/43898807
@author zxm 基于客户端分片形式的集群 采用一致性哈希
事务处理器 @author zxm @date 2020-06-02
Index ¶
- Constants
- func Connect(server string) *net.TCPConn
- func LoggerInit()
- func SendCommand(conn *net.TCPConn, cmd string, a ...[]byte) string
- type Client
- func (client *Client) Auth(pwd string) (interface{}, error)
- func (client *Client) Decr(key string) (interface{}, error)
- func (client *Client) Del(key string) (interface{}, error)
- func (client *Client) Discard() (interface{}, error)
- func (client *Client) Exec() (interface{}, error)
- func (client *Client) Expire(key string, value int64) (interface{}, error)
- func (client *Client) Get(key string) (interface{}, error)
- func (client *Client) Hdel(hash string, key string) (interface{}, error)
- func (client *Client) Hexists(hash string, key string) (interface{}, error)
- func (client *Client) Hget(hash string, key string) (interface{}, error)
- func (client *Client) Hgetall(hash string) (interface{}, error)
- func (client *Client) Hkeys(hash string) (interface{}, error)
- func (client *Client) Hlen(hash string) (interface{}, error)
- func (client *Client) Hmget(hash string, keys ...string) (interface{}, error)
- func (client *Client) Hmset(hash string, keyvalues ...string) (interface{}, error)
- func (client *Client) Hset(hash string, key string, value string) (interface{}, error)
- func (client *Client) Hvalues(hash string) (interface{}, error)
- func (client *Client) Incr(key string) (interface{}, error)
- func (client *Client) Keys(regex string) (interface{}, error)
- func (client *Client) Lindex(list string, pos int64) (interface{}, error)
- func (client *Client) LinsertAfter(list string, target string, value string) (interface{}, error)
- func (client *Client) LinsertBefore(list string, target string, value string) (interface{}, error)
- func (client *Client) Llen(list string) (interface{}, error)
- func (client *Client) Lpop(list string) (interface{}, error)
- func (client *Client) Lpush(list string, elements ...string) (interface{}, error)
- func (client *Client) Lrange(list string, start int64, end int64) (interface{}, error)
- func (client *Client) Lrem(list string, count int64, value string) (interface{}, error)
- func (client *Client) Lset(list string, pos int64, value string) (interface{}, error)
- func (client *Client) Mget(keys ...string) (interface{}, error)
- func (client *Client) Mset(keyvalues ...string) (interface{}, error)
- func (client *Client) Multi() (interface{}, error)
- func (client *Client) Ping() (interface{}, error)
- func (client *Client) Rpop(list string) (interface{}, error)
- func (client *Client) Rpush(list string, elements ...string) (interface{}, error)
- func (client *Client) Sadd(set string, elements ...string) (interface{}, error)
- func (client *Client) Scard(set string) (interface{}, error)
- func (client *Client) Sdiff(sets ...string) (interface{}, error)
- func (client *Client) Set(key string, value string) (interface{}, error)
- func (client *Client) Setex(key string, time int64, value string) (interface{}, error)
- func (client *Client) Setnx(key string, value string) (interface{}, error)
- func (client *Client) Sismember(set string, value string) (interface{}, error)
- func (client *Client) Smembers(set string) (interface{}, error)
- func (client *Client) Spop(set string) (interface{}, error)
- func (client *Client) Srandmembers(set string, count int64) (interface{}, error)
- func (client *Client) Srem(set string, elements ...string) (interface{}, error)
- func (client *Client) Ttl(key string) (interface{}, error)
- func (client *Client) Zadd(zset string, scoresvalues ...string) (interface{}, error)
- func (client *Client) Zcard(zset string) (interface{}, error)
- func (client *Client) Zrange(zset string, start int64, end int64) (interface{}, error)
- func (client *Client) ZrangeWithScores(zset string, start int64, end int64) (interface{}, error)
- func (client *Client) Zrank(zset string, value string) (interface{}, error)
- func (client *Client) Zrem(zset string, elements ...string) (interface{}, error)
- func (client *Client) Zrevrange(zset string, start int64, end int64) (interface{}, error)
- func (client *Client) ZrevrangeWithScores(zset string, start int64, end int64) (interface{}, error)
- func (client *Client) Zrevrank(zset string, value string) (interface{}, error)
- func (client *Client) Zscore(zset string, value string) (interface{}, error)
- type Cluster
- func (cluster *Cluster) Auth(pwd string) (interface{}, error)
- func (cluster *Cluster) Decr(key string) (interface{}, error)
- func (cluster *Cluster) Del(key string) (interface{}, error)
- func (cluster *Cluster) Expire(key string, value int64) (interface{}, error)
- func (cluster *Cluster) Get(key string) (interface{}, error)
- func (cluster *Cluster) GetClusterNodesInfo() []*Node
- func (cluster *Cluster) GetClusterPool() map[string]*ConnPool
- func (cluster *Cluster) Hdel(hash string, key string) (interface{}, error)
- func (cluster *Cluster) Hexists(hash string, key string) (interface{}, error)
- func (cluster *Cluster) Hget(hash string, key string) (interface{}, error)
- func (cluster *Cluster) Hgetall(hash string) (interface{}, error)
- func (cluster *Cluster) Hkeys(hash string) (interface{}, error)
- func (cluster *Cluster) Hmget(hash string, keys ...string) (interface{}, error)
- func (cluster *Cluster) Hmset(hash string, keyvalues ...string) (interface{}, error)
- func (cluster *Cluster) Hset(hash string, key string, value string) (interface{}, error)
- func (cluster *Cluster) Hvalues(hash string) (interface{}, error)
- func (cluster *Cluster) Incr(key string) (interface{}, error)
- func (cluster *Cluster) Keys(regex string) (interface{}, error)
- func (cluster *Cluster) Lindex(list string, pos int64) (interface{}, error)
- func (cluster *Cluster) LinsertAfter(list string, target string, value string) (interface{}, error)
- func (cluster *Cluster) LinsertBefore(list string, target string, value string) (interface{}, error)
- func (cluster *Cluster) Llen(list string) (interface{}, error)
- func (cluster *Cluster) Lpop(list string) (interface{}, error)
- func (cluster *Cluster) Lpush(list string, elements ...string) (interface{}, error)
- func (cluster *Cluster) Lrange(list string, start int64, end int64) (interface{}, error)
- func (cluster *Cluster) Lrem(list string, count int64, value string) (interface{}, error)
- func (cluster *Cluster) Lset(list string, pos int64, value string) (interface{}, error)
- func (cluster *Cluster) Mget(keys ...string) (interface{}, error)
- func (cluster *Cluster) Mset(keyvalues ...string) (interface{}, error)
- func (cluster *Cluster) RandomSelect() *ConnPool
- func (cluster *Cluster) Rpop(list string) (interface{}, error)
- func (cluster *Cluster) Rpush(list string, elements ...string) (interface{}, error)
- func (cluster *Cluster) Sadd(set string, elements ...string) (interface{}, error)
- func (cluster *Cluster) Scard(set string) (interface{}, error)
- func (cluster *Cluster) Sdiff(sets ...string) (interface{}, error)
- func (cluster *Cluster) SelectOne(url string) *ConnPool
- func (cluster *Cluster) Set(key string, value string) (interface{}, error)
- func (cluster *Cluster) Setex(key string, time int64, value string) (interface{}, error)
- func (cluster *Cluster) Setnx(key string, value string) (interface{}, error)
- func (cluster *Cluster) Sismember(set string, value string) (interface{}, error)
- func (cluster *Cluster) Smembers(set string) (interface{}, error)
- func (cluster *Cluster) Spop(set string) (interface{}, error)
- func (cluster *Cluster) Srandmembers(set string, count int64) (interface{}, error)
- func (cluster *Cluster) Srem(set string, elements ...string) (interface{}, error)
- func (cluster *Cluster) Ttl(key string) (interface{}, error)
- func (cluster *Cluster) Zadd(zset string, scoresvalues ...string) (interface{}, error)
- func (cluster *Cluster) Zcard(zset string) (interface{}, error)
- func (cluster *Cluster) Zrange(zset string, start int64, end int64) (interface{}, error)
- func (cluster *Cluster) ZrangeWithScores(zset string, start int64, end int64) (interface{}, error)
- func (cluster *Cluster) Zrank(zset string, value string) (interface{}, error)
- func (cluster *Cluster) Zrem(zset string, elements ...string) (interface{}, error)
- func (cluster *Cluster) Zrevrange(zset string, start int64, end int64) (interface{}, error)
- func (cluster *Cluster) ZrevrangeWithScores(zset string, start int64, end int64) (interface{}, error)
- func (cluster *Cluster) Zrevrank(zset string, value string) (interface{}, error)
- func (cluster *Cluster) Zscore(zset string, value string) (interface{}, error)
- type ClusterConfig
- type ConnConfig
- type ConnPool
- type Consistent
- type HashRing
- type Node
- type Shard
- type ShardConfig
- type ShardInfo
- type Sharding
- func (sharding *Sharding) Auth(pwd string) (interface{}, error)
- func (sharding *Sharding) Decr(key string) (interface{}, error)
- func (sharding *Sharding) Del(key string) (interface{}, error)
- func (sharding *Sharding) Expire(key string, value int64) (interface{}, error)
- func (sharding *Sharding) Get(key string) (interface{}, error)
- func (sharding *Sharding) GetShardInfo() []*Shard
- func (sharding *Sharding) GetShardingPool() map[string]*ConnPool
- func (sharding *Sharding) Hget(hash string, key string) (interface{}, error)
- func (sharding *Sharding) Hset(hash string, key string, value string) (interface{}, error)
- func (sharding *Sharding) Incr(key string) (interface{}, error)
- func (sharding *Sharding) Lindex(list string, pos int64) (interface{}, error)
- func (sharding *Sharding) LinsertAfter(list string, target string, value string) (interface{}, error)
- func (sharding *Sharding) LinsertBefore(list string, target string, value string) (interface{}, error)
- func (sharding *Sharding) Llen(list string) (interface{}, error)
- func (sharding *Sharding) Lpop(list string) (interface{}, error)
- func (sharding *Sharding) Lpush(list string, elements ...string) (interface{}, error)
- func (sharding *Sharding) Lrange(list string, start int64, end int64) (interface{}, error)
- func (sharding *Sharding) Lrem(list string, count int64, value string) (interface{}, error)
- func (sharding *Sharding) Lset(list string, pos int64, value string) (interface{}, error)
- func (sharding *Sharding) Rpop(list string) (interface{}, error)
- func (sharding *Sharding) Rpush(list string, elements ...string) (interface{}, error)
- func (sharding *Sharding) Sadd(set string, elements ...string) (interface{}, error)
- func (sharding *Sharding) Scard(set string) (interface{}, error)
- func (sharding *Sharding) Set(key string, value string) (interface{}, error)
- func (sharding *Sharding) Setex(key string, time int64, value string) (interface{}, error)
- func (sharding *Sharding) Setnx(key string, value string) (interface{}, error)
- func (sharding *Sharding) Sismember(set string, value string) (interface{}, error)
- func (sharding *Sharding) Smembers(set string) (interface{}, error)
- func (sharding *Sharding) Spop(set string) (interface{}, error)
- func (sharding *Sharding) Srandmembers(set string, count int64) (interface{}, error)
- func (sharding *Sharding) Srem(set string, elements ...string) (interface{}, error)
- func (sharding *Sharding) Ttl(key string) (interface{}, error)
- func (sharding *Sharding) Zadd(zset string, scoresvalues ...string) (interface{}, error)
- func (sharding *Sharding) Zcard(zset string) (interface{}, error)
- func (sharding *Sharding) Zrange(zset string, start int64, end int64) (interface{}, error)
- func (sharding *Sharding) ZrangeWithScores(zset string, start int64, end int64) (interface{}, error)
- func (sharding *Sharding) Zrank(zset string, value string) (interface{}, error)
- func (sharding *Sharding) Zrem(zset string, elements ...string) (interface{}, error)
- func (sharding *Sharding) Zrevrange(zset string, start int64, end int64) (interface{}, error)
- func (sharding *Sharding) ZrevrangeWithScores(zset string, start int64, end int64) (interface{}, error)
- func (sharding *Sharding) Zrevrank(zset string, value string) (interface{}, error)
- func (sharding *Sharding) Zscore(zset string, value string) (interface{}, error)
Constants ¶
View Source
const DEFAULT_REPLICAS = 160
默认每个节点的虚拟节点数量
Variables ¶
This section is empty.
Functions ¶
func LoggerInit ¶
func LoggerInit()
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
*
- gedis 客户端
func (*Client) Lrem ¶
*
- count > 0 : 从表头开始向表尾搜索,移除与 VALUE 相等的元素,数量为 COUNT 。
- count < 0 : 从表尾开始向表头搜索,移除与 VALUE 相等的元素,数量为 COUNT 的绝对值。
- count = 0 : 移除表中所有与 VALUE 相等的值。
func (*Client) Srandmembers ¶
func (*Client) ZrangeWithScores ¶
func (*Client) ZrevrangeWithScores ¶
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
*
- 集群客户端
- heartBeatInterval 心跳检测时间间隔,单位s
- clusterPool key:连接串 value:连接池
func (*Cluster) GetClusterNodesInfo ¶
func (*Cluster) GetClusterPool ¶
func (*Cluster) LinsertBefore ¶
func (cluster *Cluster) LinsertBefore(list string, target string, value string) (interface{}, error)
*
- target 目标元素
func (*Cluster) Lrem ¶
*
- count > 0 : 从表头开始向表尾搜索,移除与 VALUE 相等的元素,数量为 COUNT 。
- count < 0 : 从表尾开始向表头搜索,移除与 VALUE 相等的元素,数量为 COUNT 的绝对值。
- count = 0 : 移除表中所有与 VALUE 相等的值。
func (*Cluster) RandomSelect ¶
func (*Cluster) Srandmembers ¶
func (*Cluster) ZrangeWithScores ¶
func (*Cluster) ZrevrangeWithScores ¶
type ClusterConfig ¶
type ConnConfig ¶
type Consistent ¶
type Consistent struct { Nodes map[uint32]ShardInfo Resources map[int]bool sync.RWMutex // contains filtered or unexported fields }
func NewConsistent ¶
func NewConsistent() *Consistent
func (*Consistent) GetShardInfo ¶
func (c *Consistent) GetShardInfo(key string) ShardInfo
根据key获取分片信息
func (*Consistent) Remove ¶
func (c *Consistent) Remove(node *ShardInfo)
type Sharding ¶
type Sharding struct {
// contains filtered or unexported fields
}
*
- 客户端分片
- heartBeatInterval 心跳检测时间间隔,单位s
- shardingPool key:连接串 value:连接池
func (*Sharding) GetShardingPool ¶
获取分片连接池
func (*Sharding) LinsertAfter ¶
func (sharding *Sharding) LinsertAfter(list string, target string, value string) (interface{}, error)
*
- target 目标元素
func (*Sharding) LinsertBefore ¶
func (sharding *Sharding) LinsertBefore(list string, target string, value string) (interface{}, error)
*
- target 目标元素
func (*Sharding) Lrem ¶
*
- count > 0 : 从表头开始向表尾搜索,移除与 VALUE 相等的元素,数量为 COUNT 。
- count < 0 : 从表尾开始向表头搜索,移除与 VALUE 相等的元素,数量为 COUNT 的绝对值。
- count = 0 : 移除表中所有与 VALUE 相等的值。
func (*Sharding) Srandmembers ¶
func (*Sharding) ZrangeWithScores ¶
func (*Sharding) ZrevrangeWithScores ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.