I have a Redis implementation with 6 nodes (3 masters 3 slaves - cluster enabled). I have load in every master an amount of keys.
So, my question is:
Is it possible to actual copy one key from 127.0.0.1:30001 to 127.0.0.1:30002?
For example lets say that my key has the name "testkey". If i copy this key from 30001 to 30002, when i want to get the key from 30001 or from 30002 the response must fetch the value of "testkey" in both calls.
No, that not how it works.
Keys in the cluster are assigned to hash slots and slots are assigned to master nodes. The keys' assignment is done by hashing their names (or the hash tag in them) so it is consistent, meaning that a given key name always hashes to the same slot.
A key can exist only once in the keyspace, but the slot it belongs to can be moved between masters. To scale reads from that key you can use the slave of the applicable master.
A good point to start understanding how the cluster works is by referring to the [tutorial](https://redis.io/topics/cluster-tutorial].
Related
If two distinct keys have the same value (and say the value is large) does redis store the value twice or will it use a pointer / reference. The way git does ?
Redis stores them as two independent key-value pairs.
If you want to remove the duplication, you have to build an index from multiple keys to a shared value by yourself.
I want to use the affinity key with BinaryObject. I have used below code to set my affinity key but it didn't work. My Cache key is off type BinaryObject.
CacheKeyConfiguration keyConfiguration = new CacheKeyConfiguration(BinaryObject.class.getName(), affinityKeyConfig);
cfg.setKeyConfiguration(keyConfiguration);
I have used BinaryObject in key and value also. I have used bank as affinity key. I had inserted 4 records for 'SBI' and 8 'records for 'HDFC'. For node 1, it should show 4/8 on primary/backup and for node 2, it should show 8/4 on primary/backup.
But I can see records are equally distributed. If I use affinity key then data should not distributed equally.
I would like to have something like the following table in redis.
host name
back queue
stanford.edu
23
microsoft.com
17
As far as I know, the best way to implement this is to use redis hashes (with host name as key and back queue as value). However, in my use case, I also want to get the first key-value pair present in the hash map.
How can this be implemented? Are there any redis datatypes specifically for this?
In cluster mode of Redis, is a piece of data with a specific key has to be stored in a specific node, no matter what data structure the it has (e.g. List/Hash)?
For example, I have a hash map:
HMSET website google www.google.com yahoo www.yahoo.com
The key of the hash map is "website", and the hash map has data {google:www.google.com, yahoo:www.yahoo.com}. In my understanding, the hash map is stored in only one node of the cluster. It will be not efficient when the hash map is large (e.g. 400M key-value pairs in one hash map).
My question is: is there a way to automatically distribute the contents of the hash map of the same key among the cluster? For example, store pair {google:www.google.com} in node 0 and store pair {yahoo www.yahoo.com} in node 1, when the key of the hash map is still "website"?
In cluster mode of Redis, is a piece of data with a specific key has to be stored in a specific node, no matter what data structure the it has (e.g. List/Hash)?
Yes - every key is mapped to a hash slot, that a single cluster instance manages.
My question is: is there a way to automatically distribute the contents of the hash map of the same key among the cluster?
No - data is distributed between nodes at key level. A given key's data structure cannot be distributed between multiple shards. To distribute the data, you'll have to model it using more keys.
Correctly modeling your needs requires knowing what type of operations you'll be performing against your distributed "hash map" and their respective frequencies. Feel free to add this information to the question, or open a new one that is more focused on your requirements.
As I know from Redis cluster tutorial, cluster has only 16384 slots (0 - 16383). The hashslots are calculated by following command: CRC16 (KEY) mod 16384. So for example CRC16 of some key equals 16385 and hash slot will be 1. For another key CRC16 equals 32769 and hash slot will be again 1. Is it cause some conflict? Or first one will be rewritten by second one?
If i understand your question, no this is not a conflict. Each key belogns to one hashsolt but each hashslot can have many keys.
CLUSTER GETKEYSINSLOT slot count: https://redis.io/commands/cluster-keyslot