Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Redis Provider
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
Providers
Redis Provider
Commits
b16c6ab6
Commit
b16c6ab6
authored
1 year ago
by
astri
Browse files
Options
Downloads
Patches
Plain Diff
open close management
parent
562ad245
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
deps/Base-DAQ
+1
-1
1 addition, 1 deletion
deps/Base-DAQ
include/Redis_Provider.h
+2
-1
2 additions, 1 deletion
include/Redis_Provider.h
src/Redis_Provider.cpp
+29
-27
29 additions, 27 deletions
src/Redis_Provider.cpp
with
32 additions
and
29 deletions
Base-DAQ
@
a3e3097e
Compare
2306b743
...
a3e3097e
Subproject commit
2306b74326d9d781172e0ab65d031c36d30e872d
Subproject commit
a3e3097ede58287c647a4691670115eb395e75a0
This diff is collapsed.
Click to expand it.
include/Redis_Provider.h
+
2
−
1
View file @
b16c6ab6
...
...
@@ -15,7 +15,7 @@ namespace inaf::oasbo::Providers {
class
RedisProvider
:
public
BaseProvider
{
protected:
redisContext
*
context
;
redisContext
*
context
=
nullptr
;
std
::
string
ip
;
int
port
;
std
::
string
&
key
=
*
(
&
this
->
dest
);
...
...
@@ -43,6 +43,7 @@ public:
int
close
();
int
open
();
bool
isOpen
()
override
;
~
RedisProvider
();
};
...
...
This diff is collapsed.
Click to expand it.
src/Redis_Provider.cpp
+
29
−
27
View file @
b16c6ab6
#include
<Redis_Provider.h>
#include
<Redis_Provider.h>
using
namespace
inaf
::
oasbo
::
Providers
;
RedisProvider
::
RedisProvider
()
{
...
...
@@ -9,36 +9,21 @@ RedisProvider::RedisProvider(std::string ip, int port, std::string key) {
setIp
(
ip
);
setPort
(
port
);
setKey
(
key
);
context
=
redisConnect
(
getIp
().
c_str
(),
getPort
());
if
(
context
==
nullptr
||
context
->
err
)
{
}
int
RedisProvider
::
write
(
PacketLib
::
BasePacket
&
packet
)
{
return
write
(
packet
,
this
->
key
);
}
int
RedisProvider
::
write
(
PacketLib
::
BasePacket
&
packet
,
std
::
string
key
)
{
if
(
context
==
nullptr
||
context
->
err
){
if
(
context
)
{
std
::
cout
<<
"Redis Provider Error: "
<<
context
->
errstr
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"Redis Provider Error: Can't allocate Redis context"
<<
std
::
endl
;
}
exit
(
EXIT_FAILURE
);
}
}
int
RedisProvider
::
write
(
PacketLib
::
BasePacket
&
packet
)
{
uint
size
=
packet
.
getHeaderSize
()
+
packet
.
getPayloadSize
()
+
packet
.
getTailSize
();
redisReply
*
r
=
(
redisReply
*
)
redisCommand
(
context
,
"LPUSH %s %b"
,
this
->
key
.
c_str
(),
(
char
*
)
packet
.
getBinaryPointer
(),
size
);
if
(
r
==
NULL
)
{
// Error executing Redis command
return
-
1
;
}
// Check the type of the Redis reply
if
(
r
->
type
==
REDIS_REPLY_ERROR
)
{
// Error executing Redis command
std
::
cout
<<
r
->
str
<<
std
::
endl
;
freeReplyObject
(
r
);
return
-
1
;
}
freeReplyObject
(
r
);
return
size
;
}
int
RedisProvider
::
write
(
PacketLib
::
BasePacket
&
packet
,
std
::
string
key
)
{
uint
size
=
packet
.
getHeaderSize
()
+
packet
.
getPayloadSize
()
+
packet
.
getTailSize
();
redisReply
*
r
=
(
redisReply
*
)
redisCommand
(
context
,
"LPUSH %s %b"
,
key
.
c_str
(),
(
char
*
)
packet
.
getBinaryPointer
(),
size
);
if
(
r
==
NULL
)
{
...
...
@@ -57,15 +42,32 @@ int RedisProvider::write(PacketLib::BasePacket &packet, std::string key) {
}
int
RedisProvider
::
open
()
{
if
(
context
!=
nullptr
&&
!
context
->
err
)
close
();
context
=
redisConnect
(
getIp
().
c_str
(),
getPort
());
if
(
context
==
nullptr
||
context
->
err
)
{
if
(
context
)
{
std
::
cout
<<
"Redis Provider Error: "
<<
context
->
errstr
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"Redis Provider Error: Can't allocate Redis context"
<<
std
::
endl
;
}
return
-
1
;
}
return
1
;
}
int
RedisProvider
::
close
()
{
if
(
context
!=
nullptr
&&
!
context
->
err
){
redisFree
(
this
->
context
);
context
=
nullptr
;
}
return
1
;
}
bool
RedisProvider
::
isOpen
()
{
return
(
context
!=
nullptr
&&
!
context
->
err
);
}
RedisProvider
::~
RedisProvider
(){
if
(
context
!=
nullptr
&&
!
context
->
err
){
redisFree
(
this
->
context
);
}
close
();
}
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