Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
redis
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
redis
Merge requests
!19
Issue
#2900947
: Implement initial RedisCluster client integration
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#2900947
: Implement initial RedisCluster client integration
issue/redis-2900947:2900947-implement-initial-rediscluster
into
8.x-1.x
Overview
12
Commits
9
Pipelines
3
Changes
15
2 unresolved threads
Show all comments
Open
Adam Bramley
requested to merge
issue/redis-2900947:2900947-implement-initial-rediscluster
into
8.x-1.x
2 years ago
Overview
12
Commits
9
Pipelines
3
Changes
15
2 unresolved threads
Show all comments
Expand
0
0
Merge request reports
Compare
8.x-1.x
version 6
58c2b7e9
9 months ago
version 5
c9709e1a
1 year ago
version 4
5fd977dc
2 years ago
version 3
635b3d74
2 years ago
version 2
bf7c4f0c
2 years ago
version 1
a8d57d9e
2 years ago
8.x-1.x (HEAD)
and
latest version
latest version
e8a9ec3d
9 commits,
9 months ago
version 6
58c2b7e9
8 commits,
9 months ago
version 5
c9709e1a
6 commits,
1 year ago
version 4
5fd977dc
6 commits,
2 years ago
version 3
635b3d74
5 commits,
2 years ago
version 2
bf7c4f0c
2 commits,
2 years ago
version 1
a8d57d9e
1 commit,
2 years ago
15 files
+
721
−
27
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
15
Search (e.g. *.vue) (Ctrl+P)
src/Cache/PhpRedisCluster.php
0 → 100644
+
101
−
0
Options
<?php
namespace
Drupal\redis\Cache
;
use
Drupal\Component\Serialization\SerializationInterface
;
use
Drupal\Core\Cache\Cache
;
use
Drupal\Core\Cache\CacheTagsChecksumInterface
;
/**
* PhpRedisCluster cache backend.
*/
class
PhpRedisCluster
extends
CacheBase
{
/**
* The client.
*
* @var \RedisCluster
*/
protected
$client
;
/**
* Creates a PhpRedisCluster cache backend.
*
* @param string $bin
* The cache bin for which the object is created.
* @param \RedisCluster $client
* The cluster client.
* @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
* The cluster checksum.
* @param \Drupal\Component\Serialization\SerializationInterface $serializer
* The serialization class to use.
*/
public
function
__construct
(
$bin
,
\RedisCluster
$client
,
CacheTagsChecksumInterface
$checksum_provider
,
SerializationInterface
$serializer
)
{
parent
::
__construct
(
$bin
,
$serializer
);
$this
->
client
=
$client
;
$this
->
checksumProvider
=
$checksum_provider
;
}
/**
* {@inheritdoc}
*/
public
function
getMultiple
(
&
$cids
,
$allow_invalid
=
FALSE
)
{
// Avoid an error when there are no cache ids.
if
(
empty
(
$cids
))
{
return
[];
}
$return
=
[];
// Build the list of keys to fetch.
foreach
(
array_map
([
$this
,
'getKey'
],
$cids
)
as
$key
)
{
$result
[]
=
$this
->
client
->
hGetAll
(
$key
);
}
// Loop over the cid values to ensure numeric indexes.
foreach
(
array_values
(
$cids
)
as
$index
=>
$key
)
{
// Check if a valid result was returned from Redis.
if
(
isset
(
$result
[
$index
])
&&
is_array
(
$result
[
$index
]))
{
// Check expiration and invalidation and convert into an object.
$item
=
$this
->
expandEntry
(
$result
[
$index
],
$allow_invalid
);
if
(
$item
)
{
$return
[
$item
->
cid
]
=
$item
;
}
}
}
// Remove fetched cids from the list.
$cids
=
array_diff
(
$cids
,
array_keys
(
$return
));
return
$return
;
}
/**
* {@inheritdoc}
*/
public
function
set
(
$cid
,
$data
,
$expire
=
Cache
::
PERMANENT
,
array
$tags
=
[])
{
$ttl
=
$this
->
getExpiration
(
$expire
);
$key
=
$this
->
getKey
(
$cid
);
// If the item is already expired, delete it.
if
(
$ttl
<=
0
)
{
$this
->
delete
(
$key
);
}
// Build the cache item and save it as a hash array.
$entry
=
$this
->
createEntryHash
(
$cid
,
$data
,
$expire
,
$tags
);
$this
->
client
->
hMset
(
$key
,
$entry
);
$this
->
client
->
expire
(
$key
,
$ttl
);
}
/**
* {@inheritdoc}
*/
public
function
doDeleteMultiple
(
array
$cids
)
{
$keys
=
array_map
([
$this
,
'getKey'
],
$cids
);
$this
->
client
->
del
(
$keys
);
}
}
Loading