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
b6e8a0cd
Commit
b6e8a0cd
authored
Aug 10, 2020
by
alinamihaila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move regex in constant
parent
3b9fb330
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
1 deletion
+6
-1
lib/gitlab/redis/hll.rb
lib/gitlab/redis/hll.rb
+4
-1
spec/lib/gitlab/redis/hll_spec.rb
spec/lib/gitlab/redis/hll_spec.rb
+2
-0
No files found.
lib/gitlab/redis/hll.rb
View file @
b6e8a0cd
...
...
@@ -3,6 +3,7 @@
module
Gitlab
module
Redis
class
HLL
KEY_REGEX
=
%r{
\A
(
\w
|-|:)*
\{\w
*
\}
(
\w
|-|:)*
\z
}
.
freeze
KeyFormatError
=
Class
.
new
(
StandardError
)
def
self
.
count
(
params
)
...
...
@@ -25,8 +26,10 @@ module Gitlab
# project:{1}:set_a
# project:{1}:set_b
# project:{2}:set_c
# 2020-216-{project_action}
# i_{analytics}_dev_ops_score-2020-32
def
add
(
key
:,
value
:,
expiry
:)
unless
%r{
\A
(
\w
|-|:)*
\{\w
*
\}
(
\w
|-|:)*
\z
}
.
match?
(
key
)
unless
KEY_REGEX
.
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
...
...
spec/lib/gitlab/redis/hll_spec.rb
View file @
b6e8a0cd
...
...
@@ -14,6 +14,8 @@ RSpec.describe Gitlab::Redis::HLL, :clean_gitlab_redis_shared_state 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
expect
{
described_class
.
add
(
key:
'test:{metric}-1'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
expect
{
described_class
.
add
(
key:
'2020-216-{project_action}'
,
value:
1
,
expiry:
1
.
day
)
}.
not_to
raise_error
expect
{
described_class
.
add
(
key:
'i_{analytics}_dev_ops_score-2020-32'
,
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