Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Redis Receiver
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BIAS
Receivers
Redis Receiver
Commits
4838f1e0
Commit
4838f1e0
authored
1 year ago
by
Valerio Pastore
Browse files
Options
Downloads
Patches
Plain Diff
From Redis List to Redis Stream
parent
88e160e8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/Redis_Receiver.h
+2
-0
2 additions, 0 deletions
include/Redis_Receiver.h
src/Redis_Receiver.cpp
+25
-11
25 additions, 11 deletions
src/Redis_Receiver.cpp
with
27 additions
and
11 deletions
include/Redis_Receiver.h
+
2
−
0
View file @
4838f1e0
...
...
@@ -20,6 +20,8 @@ class RedisReceiver: public BaseProtocol {
protected:
std
::
string
key
;
redisContext
*
context
;
bool
checkRedisStream
(
redisReply
&
r
);
public:
RedisReceiver
(
std
::
string
hs
,
int
prt
,
std
::
string
topic
);
~
RedisReceiver
()
{
...
...
This diff is collapsed.
Click to expand it.
src/Redis_Receiver.cpp
+
25
−
11
View file @
4838f1e0
...
...
@@ -5,6 +5,7 @@
#include
<fstream>
#include
<map>
#include
<string.h>
#include
<sstream>
using
namespace
inaf
::
oasbo
::
ConnectionProtocols
;
...
...
@@ -12,6 +13,7 @@ RedisReceiver::RedisReceiver(std::string hs, int prt, std::string key) {
this
->
host
=
hs
;
this
->
port
=
prt
;
this
->
key
=
key
;
this
->
context
=
NULL
;
}
/*
...
...
@@ -31,9 +33,8 @@ int RedisReceiver::connectToClient() {
return
1
;
}
int
RedisReceiver
::
connectToServer
()
{
return
1
;
int
RedisReceiver
::
connectToServer
()
{
// no differences in implementation
return
connectToClient
();
}
/*
...
...
@@ -43,21 +44,34 @@ int RedisReceiver::connectToServer() {
* @return number of bytes received [-1 error, 0 done]
*/
int
RedisReceiver
::
rcvPacketFromCli
(
PacketLib
::
BasePacket
&
pack
)
{
std
::
string
cmd
(
"RPOP "
);
cmd
.
append
(
key
);
redisReply
*
r
=
(
redisReply
*
)
redisCommand
(
context
,
cmd
.
c_str
());
if
(
r
->
type
==
REDIS_REPLY_STRING
){
int
sizeRead
=
r
->
len
;
pack
.
copyToBinaryPointer
(
reinterpret_cast
<
uint8_t
*>
(
r
->
str
),
sizeRead
);
std
::
stringstream
cmd
;
cmd
<<
"XREAD BLOCK 0 STREAMS "
;
cmd
<<
key
;
cmd
<<
" $"
;
redisReply
*
r
=
(
redisReply
*
)
redisCommand
(
context
,
cmd
.
str
().
c_str
());
if
(
checkRedisStream
(
*
r
)){
redisReply
*
binaryValue
=
r
->
element
[
0
]
->
element
[
1
]
->
element
[
0
]
->
element
[
1
]
->
element
[
1
];
int
size
=
binaryValue
->
len
;
std
::
cout
<<
"len: "
<<
size
<<
std
::
endl
;
pack
.
copyToBinaryPointer
(
reinterpret_cast
<
uint8_t
*>
(
binaryValue
->
str
),
size
);
freeReplyObject
(
r
);
return
sizeRead
;
return
size
;
}
std
::
cout
<<
"FAIL"
<<
std
::
endl
;
freeReplyObject
(
r
);
return
-
1
;
}
int
RedisReceiver
::
sendPacketToSrv
(
PacketLib
::
BasePacket
&
pack
)
{
return
0
;
}
bool
RedisReceiver
::
checkRedisStream
(
redisReply
&
r
)
{
if
(
r
.
type
==
REDIS_REPLY_ARRAY
&&
r
.
element
[
0
]
!=
NULL
)
return
true
;
return
false
;
}
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