1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Add Redis Ring.

This commit is contained in:
Vladimir Mihailenco
2015-05-25 16:22:27 +03:00
parent 2c4f6f8a2c
commit 46f49a17a5
5 changed files with 348 additions and 5 deletions

View File

@ -307,7 +307,6 @@ func (opt *ClusterOptions) getMaxRedirects() int {
func (opt *ClusterOptions) clientOptions() *Options {
return &Options{
DB: 0,
Password: opt.Password,
DialTimeout: opt.DialTimeout,
@ -324,14 +323,19 @@ func (opt *ClusterOptions) clientOptions() *Options {
const hashSlots = 16384
// hashSlot returns a consistent slot number between 0 and 16383
// for any given string key.
func hashSlot(key string) int {
func hashKey(key string) string {
if s := strings.IndexByte(key, '{'); s > -1 {
if e := strings.IndexByte(key[s+1:], '}'); e > 0 {
key = key[s+1 : s+e+1]
}
}
return key
}
// hashSlot returns a consistent slot number between 0 and 16383
// for any given string key.
func hashSlot(key string) int {
key = hashKey(key)
if key == "" {
return rand.Intn(hashSlots)
}