Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nitter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TeDomum
Nitter
Commits
cd484036
Commit
cd484036
authored
4 years ago
by
Zed
Browse files
Options
Downloads
Patches
Plain Diff
Split IDs into buckets to reduce Redis mem usage
parent
b3b06545
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/redis_cache.nim
+17
-9
17 additions, 9 deletions
src/redis_cache.nim
with
17 additions
and
9 deletions
src/redis_cache.nim
+
17
−
9
View file @
cd484036
import
asyncdispatch
,
times
,
strutils
,
tables
import
asyncdispatch
,
times
,
strutils
,
tables
,
hashes
import
redis
,
redpool
,
frosty
,
supersnappy
import
types
,
api
...
...
@@ -22,7 +22,7 @@ proc migrate*(key, match: string) {.async.} =
let
list
=
await
r
.
scan
(
newCursor
(
0
),
match
,
100000
)
r
.
startPipelining
()
for
item
in
list
:
if
item
!=
"p:"
:
if
item
!=
"p:"
or
item
==
match
:
discard
await
r
.
del
(
item
)
await
r
.
setk
(
key
,
"true"
)
discard
await
r
.
flushPipeline
()
...
...
@@ -34,14 +34,19 @@ proc initRedisPool*(cfg: Config) {.async.} =
await
migrate
(
"snappyRss"
,
"rss:*"
)
await
migrate
(
"oldFrosty"
,
"*"
)
await
migrate
(
"userBuckets"
,
"p:"
)
pool
.
withAcquire
(
r
):
await
r
.
configSet
(
"hash-max-ziplist-entries"
,
"1000"
)
except
OSError
:
stdout
.
write
"Failed to connect to Redis.
\n
"
stdout
.
flushFile
quit
(
1
)
template
toKey
(
p
:
Profile
):
string
=
"p:"
&
toLower
(
p
.
username
)
template
toKey
(
l
:
List
):
string
=
toLower
(
"l:"
&
l
.
username
&
'/'
&
l
.
name
)
template
pidKey
(
name
:
string
):
string
=
"pid:"
&
$
(
hash
(
name
)
div
1_000_000
)
template
profileKey
(
name
:
string
):
string
=
"p:"
&
name
template
listKey
(
l
:
List
):
string
=
toLower
(
"l:"
&
l
.
username
&
'/'
&
l
.
name
)
proc
get
(
query
:
string
):
Future
[
string
]
{.
async
.}
=
pool
.
withAcquire
(
r
):
...
...
@@ -52,23 +57,25 @@ proc setex(key: string; time: int; data: string) {.async.} =
discard
await
r
.
setex
(
key
,
time
,
data
)
proc
cache
*
(
data
:
List
)
{.
async
.}
=
await
setex
(
data
.
t
o
Key
,
listCacheTime
,
compress
(
freeze
(
data
)))
await
setex
(
data
.
lis
tKey
,
listCacheTime
,
compress
(
freeze
(
data
)))
proc
cache
*
(
data
:
PhotoRail
;
name
:
string
)
{.
async
.}
=
await
setex
(
"pr:"
&
name
,
baseCacheTime
,
compress
(
freeze
(
data
)))
proc
cache
*
(
data
:
Profile
)
{.
async
.}
=
if
data
.
username
.
len
==
0
:
return
let
name
=
toLower
(
data
.
username
)
pool
.
withAcquire
(
r
):
r
.
startPipelining
()
discard
await
r
.
setex
(
data
.
to
Key
,
baseCacheTime
,
compress
(
freeze
(
data
)))
discard
await
r
.
hset
(
"p:"
,
toLower
(
data
.
user
name
)
,
data
.
id
)
discard
await
r
.
setex
(
name
.
profile
Key
,
baseCacheTime
,
compress
(
freeze
(
data
)))
discard
await
r
.
hset
(
name
.
pidKey
,
name
,
data
.
id
)
discard
await
r
.
flushPipeline
()
proc
cacheProfileId
*
(
username
,
id
:
string
)
{.
async
.}
=
if
username
.
len
==
0
or
id
.
len
==
0
:
return
let
name
=
toLower
(
username
)
pool
.
withAcquire
(
r
):
discard
await
r
.
hset
(
"p:"
,
toLower
(
user
name
)
,
id
)
discard
await
r
.
hset
(
name
.
pidKey
,
name
,
id
)
proc
cacheRss
*
(
query
:
string
;
rss
:
Rss
)
{.
async
.}
=
let
key
=
"rss:"
&
query
...
...
@@ -80,8 +87,9 @@ proc cacheRss*(query: string; rss: Rss) {.async.} =
discard
await
r
.
flushPipeline
()
proc
getProfileId
*
(
username
:
string
):
Future
[
string
]
{.
async
.}
=
let
name
=
toLower
(
username
)
pool
.
withAcquire
(
r
):
result
=
await
r
.
hget
(
"p:"
,
toLower
(
user
name
)
)
result
=
await
r
.
hget
(
name
.
pidKey
,
name
)
if
result
==
redisNil
:
result
.
setLen
(
0
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment