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
c27be87a
Commit
c27be87a
authored
Aug 06, 2020
by
alinamihaila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add redis hll key format validation
parent
5a27361c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
lib/gitlab/redis/hll.rb
lib/gitlab/redis/hll.rb
+6
-2
spec/lib/gitlab/redis/hll_spec.rb
spec/lib/gitlab/redis/hll_spec.rb
+17
-0
No files found.
lib/gitlab/redis/hll.rb
View file @
c27be87a
...
...
@@ -2,6 +2,8 @@
module
Gitlab
module
Redis
KeyFormatError
=
Class
.
new
(
StandardError
)
class
HLL
def
self
.
count
(
params
)
self
.
new
.
count
(
params
)
...
...
@@ -11,8 +13,6 @@ module Gitlab
self
.
new
.
add
(
params
)
end
# NOTE: It is important to make sure the keys are in the same hash slot
# https://redis.io/topics/cluster-spec#keys-hash-tags
def
count
(
keys
:)
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
redis
.
pfcount
(
*
keys
)
...
...
@@ -20,6 +20,10 @@ module Gitlab
end
def
add
(
key
:,
value
:,
expiry
:)
unless
%r{
\A
.*
\{
.*
\}
.*
\z
}
.
match?
(
key
)
raise
KeyFormatError
.
new
(
"Invalid key format.
#{
key
}
key should have changeable parts in curly braces. See https://docs.gitlab.com/ee/development/redis.html#multi-key-commands"
)
end
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
redis
.
multi
do
|
multi
|
multi
.
pfadd
(
key
,
value
)
...
...
spec/lib/gitlab/redis/hll_spec.rb
0 → 100644
View file @
c27be87a
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Redis
::
HLL
,
:clean_gitlab_redis_shared_state
do
describe
'.add'
do
it
'raise an error when using an invalid key format'
do
expect
{
described_class
.
add
(
key:
'test'
,
value:
1
,
expiry:
1
.
day
)
}.
to
raise_error
(
Gitlab
::
Redis
::
KeyFormatError
)
expect
{
described_class
.
add
(
key:
'test-{metric'
,
value:
1
,
expiry:
1
.
day
)
}.
to
raise_error
(
Gitlab
::
Redis
::
KeyFormatError
)
end
it
"doesn't raise error when having correct format"
do
expect
{
described_class
.
add
(
key:
'test-{metric}'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
expect
{
described_class
.
add
(
key:
'test-{metric}-1'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
end
end
end
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