Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
sujata
/
Akruti-Frontend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Registry
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 8334a2b2
authored
2026-04-07 16:27:48 +0530
by
Ravindra Kanojiya
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
updated redis
1 parent
048e6e11
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
4 deletions
pages/api/clear-redis.js
pages/api/clear-redis.js
View file @
8334a2b
import
redis
from
"@/lib/redis"
;
export
default
async
function
handler
(
req
,
res
)
{
if
(
req
.
method
!==
"
DELETE
"
)
{
if
(
req
.
method
!==
"
POST
"
)
{
return
res
.
status
(
405
).
json
({
error
:
"Method not allowed"
});
}
const
authKey
=
req
.
headers
[
"authorization"
]?.
replace
(
"Bearer "
,
""
);
if
(
!
authKey
||
authKey
!==
process
.
env
.
REDIS_CLEAR_CHACE_KEY
)
{
return
res
.
status
(
401
).
json
({
error
:
"Unauthorized"
});
}
const
prefix
=
process
.
env
.
REDIS_KEY_PREFIX
||
"Akruti"
;
try
{
// ⚠️ Dangerous: deletes all keys
await
redis
.
flushall
();
const
pattern
=
`
${
prefix
}
*`
;
let
cursor
=
"0"
;
let
deletedCount
=
0
;
do
{
const
[
nextCursor
,
keys
]
=
await
redis
.
scan
(
cursor
,
"MATCH"
,
pattern
,
"COUNT"
,
100
);
cursor
=
nextCursor
;
if
(
keys
.
length
>
0
)
{
await
redis
.
del
(...
keys
);
deletedCount
+=
keys
.
length
;
}
}
while
(
cursor
!==
"0"
);
return
res
.
status
(
200
).
json
({
success
:
true
,
message
:
"All Redis keys deleted"
,
message
:
`Deleted
${
deletedCount
}
keys matching prefix "
${
prefix
}
"`
,
deletedCount
,
});
}
catch
(
error
)
{
return
res
.
status
(
500
).
json
({
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment