Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nelson-ph/627ef3691b864b5d87aecaf0e50fc5dc to your computer and use it in GitHub Desktop.
Save nelson-ph/627ef3691b864b5d87aecaf0e50fc5dc to your computer and use it in GitHub Desktop.
Drupal - Redis Cluster - review Lock/PredisCluster and PredisClusterCacheTagsChecksum::getTagInvalidationCounts
Index: src/Lock/PredisCluster.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Lock/PredisCluster.php b/src/Lock/PredisCluster.php
--- a/src/Lock/PredisCluster.php (date 1619704355683)
+++ b/src/Lock/PredisCluster.php (date 1619704355683)
@@ -7,4 +7,22 @@
*/
class PredisCluster extends Predis {
+ /**
+ * @param string $name
+ *
+ * @throws \Exception
+ */
+ public function release($name) {
+ $key = $this->getKey($name);
+ $id = $this->getLockId();
+
+ unset($this->locks[$name]);
+
+ if ($this->client->get($key) == $id) {
+ $pipe = $this->client->pipeline();
+ $pipe->del([$key]);
+ $pipe->execute();
+ }
+ }
+
}
Index: src/Cache/PredisClusterCacheTagsChecksum.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Cache/PredisClusterCacheTagsChecksum.php b/src/Cache/PredisClusterCacheTagsChecksum.php
--- a/src/Cache/PredisClusterCacheTagsChecksum.php (date 1619704338261)
+++ b/src/Cache/PredisClusterCacheTagsChecksum.php (date 1619704338261)
@@ -30,4 +30,19 @@
}
}
+ /**
+ * {@inheritdoc}
+ */
+ protected function getTagInvalidationCounts(array $tags) {
+ $keys = array_map([$this, 'getTagKey'], $tags);
+
+ $pipe = $this->client->pipeline();
+ foreach ($keys as $key) {
+ $pipe->get($key);
+ }
+ $values = $pipe->execute();
+
+ return is_array($values) ? array_map('intval', array_combine($tags, $values)) : [];
+ }
+
}
Index: src/PersistentLock/PredisCluster.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/PersistentLock/PredisCluster.php b/src/PersistentLock/PredisCluster.php
--- a/src/PersistentLock/PredisCluster.php (date 1619704355687)
+++ b/src/PersistentLock/PredisCluster.php (date 1619704355687)
@@ -7,4 +7,22 @@
*/
class PredisCluster extends Predis {
+ /**
+ * @param string $name
+ *
+ * @throws \Exception
+ */
+ public function release($name) {
+ $key = $this->getKey($name);
+ $id = $this->getLockId();
+
+ unset($this->locks[$name]);
+
+ if ($this->client->get($key) == $id) {
+ $pipe = $this->client->pipeline();
+ $pipe->del([$key]);
+ $pipe->execute();
+ }
+ }
+
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment