//------------------------------hash method----------------------------------- uint8_t CRedisClient::hset(const std::string &key, const std::string &field, const std::string &value) { Command cmd( "HSET" ); cmd << key << field << value; int64_t num = 0; _getInt( cmd , num ); return num; }
uint64_t CRedisClient::lastsave() { Command cmd( "LASTSAVE" ); int64_t num; _getInt(cmd,num); return num; }
uint64_t CRedisClient::hlen(const string &key) { Command cmd( "HLEN" ); cmd << key; int64_t num = 0; _getInt( cmd, num ); return num; }
uint64_t CRedisClient::dbsize() { Command cmd( "DBSIZE" ); int64_t num; _getInt(cmd,num); return num; }
bool CRedisClient::hsetnx(const string &key, const string &field, const string &value) { Command cmd( "HSETNX" ); cmd << key << field << value; int64_t num = 0; _getInt( cmd, num ); return ( num==1 ? true:false ); }
uint64_t CRedisClient::psubnumpat() { Command cmd( "PUBSUB" ); cmd << "NUMPAT"; int64_t num = 0; _getInt( cmd, num ); return num; }
uint64_t CRedisClient::publish( const string& channel, const string& message ) { Command cmd( "PUBLISH" ); cmd << channel << message; int64_t num = 0; _getInt( cmd, num ); return num; }
bool CRedisClient::hexists(const string &key, const string &field) { Command cmd( "HEXISTS" ); cmd << key << field; int64_t num = 0; _getInt( cmd, num ); return ( num==1 ? true:false ); }
bool CRedisClient::sismember(const string &key, const string &member) { Command cmd( "SISMEMBER" ); cmd << key << member; int64_t num = 0; _getInt( cmd, num ); return ( num == 1 ? true: false ); }
bool RedisClient::exists( const string& key ) { BuildCommand cmd("EXISTS"); cmd << key; SInt64 num = 0; _getInt(cmd, num); return num; }
int64_t CRedisClient::hincrby(const string &key, const string &field, int64_t increment) { Command cmd( "HINCRBY" ); cmd << key << field << increment; int64_t num = 0; _getInt( cmd, num ); return num; }
bool RedisClient::renameNx( const string& key , const string& newKey ) { BuildCommand cmd("RENAMENX"); SInt64 num = 0; cmd << key << newKey; if ( _getInt(cmd, num) ) { return num; } return false; }
string RedisClient::object( const EobjSubCommand& subcommand , const string& key ) { BuildCommand cmd("OBJECT"); SInt64 num = 0; string retStr; std::stringstream ss; switch ( subcommand ) { case REFCOUNT : cmd << "REFCOUNT" << key; if ( _getInt(cmd, num) ) { ss << num; return ss.str(); } break; case IDLETIME : cmd << "IDLETIME" << key; if ( _getInt(cmd, num) ) { ss << num; return ss.str(); } break; case ENCODING : cmd << "ENCODING" << key; if ( _getString(cmd, retStr) ) { return retStr; } break; } return REDIS_NIL; }
uint64_t CRedisClient::sunionstroe(const string &dest, const CRedisClient::VecString &keys) { Command cmd( "SUNIONSTORE" ); cmd << dest; VecString::const_iterator it = keys.begin(); VecString::const_iterator end = keys.end(); for ( ; it != end; ++it ) { cmd << *it; } int64_t num; _getInt( cmd, num ); return num; }
uint64_t CRedisClient::sinterstore( const string& destKey ,const CRedisClient::VecString &keys ) { Command cmd( "SINTERSTORE" ); cmd << destKey; VecString::const_iterator it = keys.begin(); VecString::const_iterator end = keys.end(); for ( ; it != end; ++it ) { cmd << *it; } int64_t num = 0; _getInt( cmd, num ); return num; }
uint64_t CRedisClient::sadd(const string &key, const CRedisClient::VecString &members) { Command cmd( "SADD" ); cmd << key; VecString::const_iterator it = members.begin(); VecString::const_iterator end = members.end(); for ( ; it != end ; ++it ) { cmd << *it; } int64_t num; _getInt( cmd , num ); return num; }
SInt64 RedisClient::del( RedisClient::VecString &keys ) { BuildCommand cmd("DEL"); VecString::const_iterator it = keys.begin(); VecString::const_iterator end = keys.end(); for ( ; it != end ; ++it ) { cmd << *it; } SInt64 num = 0; _getInt(cmd, num); return num; }
uint64_t CRedisClient::hdel( const string &key, const CRedisClient::VecString &fields ) { Command cmd( "HDEL" ); cmd << key; VecString::const_iterator it = fields.begin(); VecString::const_iterator end = fields.end(); for ( ; it != end; ++it ) { cmd << *it; } int64_t num = 0; _getInt( cmd , num ); return num; }