Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
581c7c49
Commit
581c7c49
authored
Nov 15, 2021
by
nmilojevic1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add validation for primary and secondary stores
parent
7b4de75b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
lib/gitlab/redis/multi_store.rb
lib/gitlab/redis/multi_store.rb
+9
-3
spec/lib/gitlab/redis/multi_store_spec.rb
spec/lib/gitlab/redis/multi_store_spec.rb
+20
-0
No files found.
lib/gitlab/redis/multi_store.rb
View file @
581c7c49
...
@@ -40,12 +40,11 @@ module Gitlab
...
@@ -40,12 +40,11 @@ module Gitlab
)
.
freeze
)
.
freeze
def
initialize
(
primary_store
,
secondary_store
,
instance_name
=
nil
)
def
initialize
(
primary_store
,
secondary_store
,
instance_name
=
nil
)
raise
ArgumentError
,
'primary_store is required'
unless
primary_store
raise
ArgumentError
,
'secondary_store is required'
unless
secondary_store
@primary_store
=
primary_store
@primary_store
=
primary_store
@secondary_store
=
secondary_store
@secondary_store
=
secondary_store
@instance_name
=
instance_name
@instance_name
=
instance_name
validate_stores!
end
end
READ_COMMANDS
.
each
do
|
name
|
READ_COMMANDS
.
each
do
|
name
|
...
@@ -198,6 +197,13 @@ module Gitlab
...
@@ -198,6 +197,13 @@ module Gitlab
@method_missing_counter
.
increment
(
command:
command_name
,
innamece_name:
instance_name
)
@method_missing_counter
.
increment
(
command:
command_name
,
innamece_name:
instance_name
)
end
end
def
validate_stores!
raise
ArgumentError
,
'primary_store is required'
unless
primary_store
raise
ArgumentError
,
'secondary_store is required'
unless
secondary_store
raise
ArgumentError
,
'invalid primary_store'
unless
primary_store
.
is_a?
(
::
Redis
)
raise
ArgumentError
,
'invalid secondary_store'
unless
secondary_store
.
is_a?
(
::
Redis
)
end
def
log_error
(
exception
,
command_name
,
extra
=
{})
def
log_error
(
exception
,
command_name
,
extra
=
{})
Gitlab
::
ErrorTracking
.
log_exception
(
Gitlab
::
ErrorTracking
.
log_exception
(
exception
,
exception
,
...
...
spec/lib/gitlab/redis/multi_store_spec.rb
View file @
581c7c49
...
@@ -48,6 +48,26 @@ RSpec.describe Gitlab::Redis::MultiStore do
...
@@ -48,6 +48,26 @@ RSpec.describe Gitlab::Redis::MultiStore do
end
end
end
end
context
'when primary_store is not a ::Redis instance'
do
before
do
allow
(
primary_store
).
to
receive
(
:is_a?
).
with
(
::
Redis
).
and_return
(
false
)
end
it
'fails with exception'
do
expect
{
described_class
.
new
(
primary_store
,
secondary_store
,
instance_name
)
}.
to
raise_error
(
ArgumentError
,
/invalid primary_store/
)
end
end
context
'when secondary_store is not a ::Redis instance'
do
before
do
allow
(
secondary_store
).
to
receive
(
:is_a?
).
with
(
::
Redis
).
and_return
(
false
)
end
it
'fails with exception'
do
expect
{
described_class
.
new
(
primary_store
,
secondary_store
,
instance_name
)
}.
to
raise_error
(
ArgumentError
,
/invalid secondary_store/
)
end
end
context
'with READ redis commands'
do
context
'with READ redis commands'
do
let_it_be
(
:key1
)
{
"redis:{1}:key_a"
}
let_it_be
(
:key1
)
{
"redis:{1}:key_a"
}
let_it_be
(
:key2
)
{
"redis:{1}:key_b"
}
let_it_be
(
:key2
)
{
"redis:{1}:key_b"
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment