mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Redis: Fix sync erase, add btest for it
This commit is contained in:
parent
e6f1eea1b7
commit
b067a6e588
3 changed files with 64 additions and 13 deletions
|
@ -447,9 +447,6 @@ void Redis::HandleGetResult(redisReply* reply, OperationResultCallback* callback
|
||||||
void Redis::HandleEraseResult(redisReply* reply, OperationResultCallback* callback) {
|
void Redis::HandleEraseResult(redisReply* reply, OperationResultCallback* callback) {
|
||||||
--active_ops;
|
--active_ops;
|
||||||
|
|
||||||
if ( callback->IsSyncCallback() )
|
|
||||||
reply_queue.push_back(reply);
|
|
||||||
else {
|
|
||||||
OperationResult res{ReturnCode::SUCCESS};
|
OperationResult res{ReturnCode::SUCCESS};
|
||||||
|
|
||||||
if ( ! connected )
|
if ( ! connected )
|
||||||
|
@ -462,7 +459,6 @@ void Redis::HandleEraseResult(redisReply* reply, OperationResultCallback* callba
|
||||||
freeReplyObject(reply);
|
freeReplyObject(reply);
|
||||||
CompleteCallback(callback, res);
|
CompleteCallback(callback, res);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Redis::HandleGeneric(redisReply* reply) {
|
void Redis::HandleGeneric(redisReply* reply) {
|
||||||
--active_ops;
|
--active_ops;
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
open_result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<opaque of BackendHandleVal>]
|
||||||
|
put result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
||||||
|
get result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=value1234]
|
||||||
|
get result same as inserted, T
|
||||||
|
erase result, [code=Storage::SUCCESS, error_str=<uninitialized>, value=<uninitialized>]
|
||||||
|
get result 2, [code=Storage::KEY_NOT_FOUND, error_str=<uninitialized>, value=<uninitialized>]
|
|
@ -0,0 +1,48 @@
|
||||||
|
# @TEST-DOC: Tests basic Redis storage backend functions in sync mode, including overwriting
|
||||||
|
|
||||||
|
# @TEST-REQUIRES: have-redis
|
||||||
|
# @TEST-PORT: REDIS_PORT
|
||||||
|
|
||||||
|
# @TEST-EXEC: btest-bg-run redis-server run-redis-server ${REDIS_PORT%/tcp}
|
||||||
|
# @TEST-EXEC: zeek -b %INPUT | sed 's|=[0-9]*/tcp|=xxxx/tcp|g' > out
|
||||||
|
# @TEST-EXEC: btest-bg-wait -k 0
|
||||||
|
|
||||||
|
# @TEST-EXEC: btest-diff out
|
||||||
|
|
||||||
|
@load base/frameworks/storage/sync
|
||||||
|
@load policy/frameworks/storage/backend/redis
|
||||||
|
|
||||||
|
# Create a typename here that can be passed down into open_backend()
|
||||||
|
type str: string;
|
||||||
|
|
||||||
|
event zeek_init()
|
||||||
|
{
|
||||||
|
local opts: Storage::BackendOptions;
|
||||||
|
opts$redis = [ $server_host="127.0.0.1", $server_port=to_port(getenv(
|
||||||
|
"REDIS_PORT")), $key_prefix="testing" ];
|
||||||
|
|
||||||
|
local key = "key1234";
|
||||||
|
local value = "value1234";
|
||||||
|
|
||||||
|
local open_res = Storage::Sync::open_backend(Storage::REDIS, opts, str, str);
|
||||||
|
print "open_result", open_res;
|
||||||
|
|
||||||
|
local b = open_res$value;
|
||||||
|
|
||||||
|
local res = Storage::Sync::put(b, [ $key=key, $value=value ]);
|
||||||
|
print "put result", res;
|
||||||
|
|
||||||
|
res = Storage::Sync::get(b, key);
|
||||||
|
print "get result", res;
|
||||||
|
if ( res$code == Storage::SUCCESS && res?$value )
|
||||||
|
print "get result same as inserted", value == ( res$value as string );
|
||||||
|
|
||||||
|
res = Storage::Sync::erase(b, key);
|
||||||
|
print "erase result", res;
|
||||||
|
|
||||||
|
res = Storage::Sync::get(b, key);
|
||||||
|
if ( res$code != Storage::SUCCESS )
|
||||||
|
print "get result 2", res;
|
||||||
|
|
||||||
|
Storage::Sync::close_backend(b);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue