Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
fd859451
Unverified
Commit
fd859451
authored
May 18, 2023
by
OptimismBot
Committed by
GitHub
May 18, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5709 from ethereum-optimism/felipe/redis-namespace
feat(proxyd): redis namespace
parents
47854533
74f6f566
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
7 deletions
+18
-7
cache.go
proxyd/cache.go
+14
-5
config.go
proxyd/config.go
+2
-1
caching.toml
proxyd/integration_tests/testdata/caching.toml
+1
-0
proxyd.go
proxyd/proxyd.go
+1
-1
No files found.
proxyd/cache.go
View file @
fd859451
...
...
@@ -2,6 +2,7 @@ package proxyd
import
(
"context"
"strings"
"time"
"github.com/go-redis/redis/v8"
...
...
@@ -43,16 +44,24 @@ func (c *cache) Put(ctx context.Context, key string, value string) error {
}
type
redisCache
struct
{
rdb
*
redis
.
Client
rdb
*
redis
.
Client
prefix
string
}
func
newRedisCache
(
rdb
*
redis
.
Client
)
*
redisCache
{
return
&
redisCache
{
rdb
}
func
newRedisCache
(
rdb
*
redis
.
Client
,
prefix
string
)
*
redisCache
{
return
&
redisCache
{
rdb
,
prefix
}
}
func
(
c
*
redisCache
)
namespaced
(
key
string
)
string
{
if
c
.
prefix
==
""
{
return
key
}
return
strings
.
Join
([]
string
{
c
.
prefix
,
key
},
":"
)
}
func
(
c
*
redisCache
)
Get
(
ctx
context
.
Context
,
key
string
)
(
string
,
error
)
{
start
:=
time
.
Now
()
val
,
err
:=
c
.
rdb
.
Get
(
ctx
,
key
)
.
Result
()
val
,
err
:=
c
.
rdb
.
Get
(
ctx
,
c
.
namespaced
(
key
)
)
.
Result
()
redisCacheDurationSumm
.
WithLabelValues
(
"GET"
)
.
Observe
(
float64
(
time
.
Since
(
start
)
.
Milliseconds
()))
if
err
==
redis
.
Nil
{
...
...
@@ -66,7 +75,7 @@ func (c *redisCache) Get(ctx context.Context, key string) (string, error) {
func
(
c
*
redisCache
)
Put
(
ctx
context
.
Context
,
key
string
,
value
string
)
error
{
start
:=
time
.
Now
()
err
:=
c
.
rdb
.
SetEX
(
ctx
,
key
,
value
,
redisTTL
)
.
Err
()
err
:=
c
.
rdb
.
SetEX
(
ctx
,
c
.
namespaced
(
key
)
,
value
,
redisTTL
)
.
Err
()
redisCacheDurationSumm
.
WithLabelValues
(
"SETEX"
)
.
Observe
(
float64
(
time
.
Since
(
start
)
.
Milliseconds
()))
if
err
!=
nil
{
...
...
proxyd/config.go
View file @
fd859451
...
...
@@ -32,7 +32,8 @@ type CacheConfig struct {
}
type
RedisConfig
struct
{
URL
string
`toml:"url"`
URL
string
`toml:"url"`
Namespace
string
`toml:"namespace"`
}
type
MetricsConfig
struct
{
...
...
proxyd/integration_tests/testdata/caching.toml
View file @
fd859451
...
...
@@ -6,6 +6,7 @@ response_timeout_seconds = 1
[redis]
url
=
"$REDIS_URL"
namespace
=
"proxyd"
[cache]
enabled
=
true
...
...
proxyd/proxyd.go
View file @
fd859451
...
...
@@ -236,7 +236,7 @@ func Start(config *Config) (*Server, func(), error) {
log
.
Warn
(
"redis is not configured, using in-memory cache"
)
cache
=
newMemoryCache
()
}
else
{
cache
=
newRedisCache
(
redisClient
)
cache
=
newRedisCache
(
redisClient
,
config
.
Redis
.
Namespace
)
}
// Ideally, the BlocKSyncRPCURL should be the sequencer or a HA replica that's not far behind
ethClient
,
err
:=
ethclient
.
Dial
(
blockSyncRPCURL
)
...
...
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