MCPcopy Create free account
hub / github.com/F-Stack/f-stack / slotToKeyUpdateKey

Function slotToKeyUpdateKey

app/redis-6.2.6/src/db.c:1916–1933  ·  view source on GitHub ↗

Slot to Key API. This is used by Redis Cluster in order to obtain in * a fast way a key that belongs to a specified hash slot. This is useful * while rehashing the cluster and in other conditions when we need to * understand if we have keys for a given hash slot. */

Source from the content-addressed store, hash-verified

1914 * while rehashing the cluster and in other conditions when we need to
1915 * understand if we have keys for a given hash slot. */
1916void slotToKeyUpdateKey(sds key, int add) {
1917 size_t keylen = sdslen(key);
1918 unsigned int hashslot = keyHashSlot(key,keylen);
1919 unsigned char buf[64];
1920 unsigned char *indexed = buf;
1921
1922 server.cluster->slots_keys_count[hashslot] += add ? 1 : -1;
1923 if (keylen+2 > 64) indexed = zmalloc(keylen+2);
1924 indexed[0] = (hashslot >> 8) & 0xff;
1925 indexed[1] = hashslot & 0xff;
1926 memcpy(indexed+2,key,keylen);
1927 if (add) {
1928 raxInsert(server.cluster->slots_to_keys,indexed,keylen+2,NULL,NULL);
1929 } else {
1930 raxRemove(server.cluster->slots_to_keys,indexed,keylen+2,NULL);
1931 }
1932 if (indexed != buf) zfree(indexed);
1933}
1934
1935void slotToKeyAdd(sds key) {
1936 slotToKeyUpdateKey(key,1);

Callers 2

slotToKeyAddFunction · 0.85
slotToKeyDelFunction · 0.85

Calls 7

sdslenFunction · 0.85
keyHashSlotFunction · 0.85
zmallocFunction · 0.85
raxInsertFunction · 0.85
raxRemoveFunction · 0.85
zfreeFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected