Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-cicd
csst-dag
Commits
5d54f74a
Commit
5d54f74a
authored
Jan 13, 2025
by
BO ZHANG
🏀
Browse files
update Redis and tests
parent
b0981e72
Changes
2
Hide whitespace changes
Inline
Side-by-side
csst_dag/redis.py
View file @
5d54f74a
...
...
@@ -5,13 +5,25 @@ import os
redis_config_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"redis_config.toml"
)
REDIS_CONFIG
=
toml
.
load
(
redis_config_path
)
REDIS_QNAME
=
"csst_data_list"
class
Redis
(
redis
.
Redis
):
def
__init__
(
self
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
self
.
name
=
REDIS_QNAME
def
__init__
(
self
,
location
=
"naoc"
):
if
location
not
in
REDIS_CONFIG
.
keys
():
print
(
"Available redis locations: "
,
list
(
REDIS_CONFIG
.
keys
()))
raise
ValueError
(
f
"Unknown redis location:
{
location
}
"
)
super
().
__init__
(
host
=
REDIS_CONFIG
[
location
][
"host"
],
port
=
REDIS_CONFIG
[
location
][
"port"
],
db
=
REDIS_CONFIG
[
location
][
"db"
],
password
=
REDIS_CONFIG
[
location
][
"password"
],
)
self
.
qname
=
password
=
REDIS_CONFIG
[
location
][
"qname"
]
self
.
config
=
REDIS_CONFIG
[
location
]
print
(
"Setting redis config:"
)
for
k
,
v
in
self
.
config
.
items
():
print
(
f
" -
{
k
}
:
{
v
}
"
)
def
push
(
self
,
msg
):
self
.
lpush
(
self
.
name
,
msg
)
...
...
@@ -20,18 +32,10 @@ class Redis(redis.Redis):
return
self
.
rpop
(
self
.
name
)
def
get_all
(
self
):
return
self
.
lrange
(
self
.
name
,
0
,
-
1
)
def
get_redis
(
location
=
"naoc"
):
print
(
"Available redis locations: "
,
list
(
REDIS_CONFIG
.
keys
()))
if
location
not
in
REDIS_CONFIG
.
keys
():
raise
ValueError
(
f
"Unknown redis location:
{
location
}
"
)
return
Redis
(
**
REDIS_CONFIG
[
location
])
return
self
.
lrange
(
self
.
qname
,
0
,
-
1
)
# msgs = r.lrange(name, 0, -1)
#
# for chipid in range(6, 26):
# this_msg = gen_msg(
# dag_id="csst-msc-l1-mbi", obsid="11009101682009", chipid=f"{chipid:02d}"
...
...
@@ -42,6 +46,5 @@ def get_redis(location="naoc"):
# msgs = r.lrange(name, 0, -1)
# print(msgs)
#
#
# msgs_later = r.lrange(name, 0, -1)
# print(msgs_later)
tests/test_redis.py
View file @
5d54f74a
from
csst_dag
import
get_r
edis
from
csst_dag
.redis
import
R
edis
def
test_redis_naoc
():
r
=
get_redis
(
"naoc"
)
r
=
Redis
(
location
=
"naoc"
)
print
(
r
)
assert
r
.
name
==
"csst_data_list"
assert
len
(
r
.
get_all
())
==
0
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment