C++ and Python wrapper to facilitate key-value store with the Redis database.
- Launch Redis server on
127.0.0.1:6379 - C++
- Import the header file into the C++ source file i.e.
#include "parameter_server/brosdb.h" - The header file contains
set()andget()functions to facilitate key-value store in the Redis database. - The function
set()is declared as follows,andtemplate<typename T> void set(std::string key, T value);
get()astemplate<typename T> void get(std::string key, T *value);
- The key is expected to of type
std::string. Value can be either primitive or user defined. - Source file needs to be linked against
lhiredis.
- Import the header file into the C++ source file i.e.
- Python
- Import
setDataandgetDatafrombrosdbfrom brosdb import setData, getData
- The module contains
setData()andgetData()functions to facilitate key-value store in the Redis database. - The function
setData()is declared as follows,anddef setData(key, value)
getData()asdef getData(key, defaultValue = None)
- The key is expected to be of type
str.
- Import
- C++
#include <bits/stdc++.h> #include "parameter_server/brosdb.h" int main() { int a=5; std::string str("foo"); brosdb::set(str, a); int b; brosdb::get(str, &b); std::cout<<b; }
- Python
from brosdb import setData, getData setData("foo", "bar") value = getData("foo") print(value)