Async::RedisSourceAsyncRedisClusterClient

class ClusterClient

Nested

Definitions

def initialize(endpoints, **options)

Create a new instance of the cluster client.

Implementation

def initialize(endpoints, **options)
	@endpoints = endpoints
	@shards = nil
end

def crc16(bytes)

This is the CRC16 algorithm used by Redis Cluster to hash keys. Copied from https://github.com/antirez/redis-rb-cluster/blob/master/crc16.rb

Implementation

def crc16(bytes)
	sum = 0
	
	bytes.each_byte do |byte|
		sum = ((sum << 8) & 0xffff) ^ XMODEM_CRC16_LOOKUP[((sum >> 8) ^ byte) & 0xff]
	end
	
	return sum
end

def slot_for(key)

Return Redis::Client for a given key. Modified from https://github.com/antirez/redis-rb-cluster/blob/master/cluster.rb#L104-L117

Implementation

def slot_for(key)
	key = key.to_s
	
	if s = key.index("{")
		if e = key.index("}", s + 1) and e != s + 1
			key = key[s + 1..e - 1]
		end
	end
	
	return crc16(key) % HASH_SLOTS
end