Granada  1.54.0
Structured layer on top of C++ REST SDK for building server applications in C++. Granada implements sessions, server side plug-in framework, C++ OAuth 2.0 server, data storage access, server script running, server browsing.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Static Protected Attributes | List of all members
granada::cache::RedisCacheDriver Class Reference

#include <redis_cache_driver.h>

Inheritance diagram for granada::cache::RedisCacheDriver:
granada::cache::CacheHandler

Public Member Functions

 RedisCacheDriver ()
 
virtual ~RedisCacheDriver ()
 
virtual const bool Exists (const std::string &key)
 
virtual const bool Exists (const std::string &hash, const std::string &key)
 
virtual const std::string Read (const std::string &key)
 
virtual const std::string Read (const std::string &hash, const std::string &key)
 
virtual void Write (const std::string &key, const std::string &value)
 
virtual void Write (const std::string &hash, const std::string &key, const std::string &value)
 
virtual void Destroy (const std::string &key)
 
virtual void Destroy (const std::string &hash, const std::string &key)
 
virtual bool Rename (const std::string &old_key, const std::string &new_key)
 
redisclient::RedisValue Scan (const std::string &cursor, const std::string &expression_)
 
redisclient::RedisValue Keys (const std::string &expression_)
 
virtual std::unique_ptr
< granada::cache::CacheHandlerIterator
make_iterator (const std::string &expression)
 
- Public Member Functions inherited from granada::cache::CacheHandler
 CacheHandler ()
 
virtual ~CacheHandler ()
 
virtual const void Match (const std::string &expression, std::vector< std::string > &keys)
 

Static Protected Attributes

static std::unique_ptr
< RedisSyncClientWrapper
redis_
 
static std::mutex mtx_
 

Detailed Description

Manages the cache storing key-value pairs or sets of key-value pairs using redis data structure server (http://redis.io/). It uses redisclient by Alex Nekipelov https://github.com/nekipelov/redisclient This code is multi-thread safe.

Constructor & Destructor Documentation

granada::cache::RedisCacheDriver::RedisCacheDriver ( )
inline

Controler

virtual granada::cache::RedisCacheDriver::~RedisCacheDriver ( )
inlinevirtual

Destructor

Member Function Documentation

virtual void granada::cache::RedisCacheDriver::Destroy ( const std::string &  key)
virtual

Destroys a key-value pair or a set of values.

Parameters
keyKey of the value or name of the set to destroy.

Implements granada::cache::CacheHandler.

virtual void granada::cache::RedisCacheDriver::Destroy ( const std::string &  hash,
const std::string &  key 
)
virtual

Destroys a key-value pair stored in a set.

Parameters
hashName of the set where the key-value pair is stored.
keyKey associated with the value.

Implements granada::cache::CacheHandler.

virtual const bool granada::cache::RedisCacheDriver::Exists ( const std::string &  key)
virtual

Checks if a key exist in the cache.

Parameters
keyKey to check.

Implements granada::cache::CacheHandler.

virtual const bool granada::cache::RedisCacheDriver::Exists ( const std::string &  hash,
const std::string &  key 
)
virtual

Checks if a key exist in a set with given hash.

Parameters
hashName of the set of key-value.
keyKey of the value
Returns
True if exist, false if it does not.

Implements granada::cache::CacheHandler.

redisclient::RedisValue granada::cache::RedisCacheDriver::Keys ( const std::string &  expression_)

Returns a RedisValue containing all the keys of the cache that match a given expression.

Parameters
expressionExpression used to match keys.
               Example of expression:

                   session:value:*
                   => will retrieve all the keys that start with
                   session:values: stored in the cache.

                   *:value:*
                   => will retrieve all the keys that contain
                   ":value:"
Returns
RedisValue containing all the keys.
virtual std::unique_ptr<granada::cache::CacheHandlerIterator> granada::cache::RedisCacheDriver::make_iterator ( const std::string &  expression)
inlinevirtual

Returns an iterator to iterate over keys with an expression.

Parameters
Expressionto be use to iterate over keys that match this expression. Example: "user*" => we will iterate over all the keys that start with "user"
Returns
Iterator.

Implements granada::cache::CacheHandler.

virtual const std::string granada::cache::RedisCacheDriver::Read ( const std::string &  key)
virtual

Returns the value associated with the given key.

Parameters
keyKey associated with the value.
Returns
Value.

Implements granada::cache::CacheHandler.

virtual const std::string granada::cache::RedisCacheDriver::Read ( const std::string &  hash,
const std::string &  key 
)
virtual

Returns the value stored in a set and associated with the given key.

Parameters
hashName of the set where the key-value pairs are stored.
keyKey associated with the value.
Returns
Value.

Implements granada::cache::CacheHandler.

virtual bool granada::cache::RedisCacheDriver::Rename ( const std::string &  old_key,
const std::string &  new_key 
)
virtual

Renames a key if it does not already exists.

Parameters
old_keyOld key to rename.
new_keyNew key.
Returns
True if the key could be renamed, false if not, for example it will return false if the new key already existed.

Implements granada::cache::CacheHandler.

redisclient::RedisValue granada::cache::RedisCacheDriver::Scan ( const std::string &  cursor,
const std::string &  expression_ 
)

Returns a RedisValue containing a group of keys of the cache that match a given expression for a given cursor, returns also a new cursor to obtain a new group of keys.

Parameters
expressionExpression used to match keys.
               Example of expression:

                   session:value:*
                   => will retrieve all the keys that start with
                   session:values: stored in the cache.

                   *:value:*
                   => will retrieve all the keys that contain
                   ":value:"
Returns
RedisValue containing a group keys and a new cursor.
virtual void granada::cache::RedisCacheDriver::Write ( const std::string &  key,
const std::string &  value 
)
virtual

Inserts a key-value pair, rewrites it if it already exists.

Parameters
keyKey to identify the value.
valueValue

Implements granada::cache::CacheHandler.

virtual void granada::cache::RedisCacheDriver::Write ( const std::string &  hash,
const std::string &  key,
const std::string &  value 
)
virtual

Inserts or rewrite a key-value pair in a set with the given name. If the set does not exist, it creates it.

Parameters
hashName of the set.
keyKey to identify the value inside the set.
valueValue

Implements granada::cache::CacheHandler.

Member Data Documentation

std::mutex granada::cache::RedisCacheDriver::mtx_
staticprotected

Mutex for thread safety.

std::unique_ptr<RedisSyncClientWrapper> granada::cache::RedisCacheDriver::redis_
staticprotected

Redis client.


The documentation for this class was generated from the following file: