Skip to content

Commit

Permalink
Select db on new redis context
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Nov 23, 2022
1 parent bf07a27 commit 27b8cde
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions rust/nvtcache/src/nvtcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ pub mod nvtcache {
impl NvtCache {
/// initialize the NVT Cache.
pub fn init() -> Result<NvtCache> {
let mut rctx = RedisCtx::new()?;
let kbi = rctx.select_database()?;
let rctx = RedisCtx::new()?;
Ok(NvtCache {
cache: rctx,
init: true,
Expand Down
9 changes: 6 additions & 3 deletions rust/nvtcache/src/redisconnector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ pub mod redisconnector {
pub fn new() -> Result<RedisCtx> {
let client = redis::Client::open(REDIS_DEFAULT_PATH)?;
let kb = client.get_connection()?;
Ok(RedisCtx {
let mut redisctx = RedisCtx {
kb,
db: 0,
maxdb: 0,
})
};
let _kbi = redisctx.select_database()?;
Ok(redisctx)
}

pub fn max_db_index(&mut self) -> Result<u32> {
Expand Down Expand Up @@ -88,7 +90,8 @@ pub mod redisconnector {
}

pub fn try_database(&mut self, dbi: u32) -> Result<u32> {
return Ok(1);
let kbi = self.kb.hset_nx(GLOBAL_DBINDEX_NAME, dbi, 1)?;
Ok(kbi)
}

pub fn select_database(&mut self) -> Result<u32> {
Expand Down

0 comments on commit 27b8cde

Please sign in to comment.