eyjian / r3c Goto Github PK
View Code? Open in Web Editor NEWRedis C++ Client
License: Apache License 2.0
Redis C++ Client
License: Apache License 2.0
使用R3C存储 json 字符串
nlohmann::json j;
j["file"] = "demo.mp3";
std::string val = j.dump();
std::cout<<"json string "<<val<<std::endl;
if (!rc.hset("domain/f", "domain", val))
存储格式为
{"file":"demo.mp3"},
使用R3C 读取的字符串没有问题,
但是实验redis客户端读取出来,多一个反斜杠,hget domain/f domain
"{"file":"demo.mp3"}"
这个编辑器好像去掉了,附上一张图片。
使用nginx, lua客户端端读取也是带反斜杠的。
有没有简单的解决思路?
bool CRedisClient::lpop(const std::string& key, std::string* value, Node* which, int num_retries)
{
CommandArgs cmd_args;
cmd_args.set_key(key);
cmd_args.set_command("LPOP");
cmd_args.add_arg(cmd_args.get_command());
cmd_args.add_arg(key);
cmd_args.final();
// Bulk string reply: the value of the first element, or nil when key does not exist.
const RedisReplyHelper redis_reply = redis_command(false, num_retries, key, cmd_args, which);
if (REDIS_REPLY_NIL == redis_reply->type)
return false;
if (REDIS_REPLY_STRING == redis_reply->type)
return get_value(redis_reply.get(), value);
return true; // MULTI & EXEC the type always is REDIS_REPLY_STATUS
}
redis_command
第一个参数is_read_command
被设为false
,导致异步模式下redisReply
直接被丢弃
hi
Will you be able to support C++17. Primarily dynamic exception specifications like throw (CRedisException);
are no more supported.
When I do make,
/usr/bin/c++ -g -rdynamic CMakeFiles/r3c_test.dir/r3c_test.cpp.o -o r3c_test -L/r3c -L/r3c/HIREDIS_LIB-NOTFOUND -Wl,-rpath,/r3c:/r3c/HIREDIS_LIB-NOTFOUND -Wl,-Bstatic -lr3c -lhiredis -Wl,-Bdynamic
fails with error /usr/bin/ld: cannot find -lhiredis
If I remove extra -Wl,
before -Bstatic,
it works. Mean
/usr/bin/c++ -g -rdynamic CMakeFiles/r3c_test.dir/r3c_test.cpp.o -o r3c_test -L/r3c -L/r3c/HIREDIS_LIB-NOTFOUND -Wl,-rpath,/r3c:/r3c/HIREDIS_LIB-NOTFOUND -Bstatic -lr3c -lhiredis -Wl,-Bdynamic
works.
Typo in rpush function
---a/r3c.cpp
+++ b/r3c.cpp
@@ -880,7 +880,7 @@ bool CRedisClient::rpop(const std::string& key, std::string* value, std::pair<st
int CRedisClient::rpush(const std::string& key, const std::string& value, std::pair<std::string, uint16_t>* which) throw (CRedisException)
{
std::vector<std::string> values(1, value);
- return rpush(key, value, which);
+ return rpush(key, values, which);
}
Sorry for opening an issue for this, I did not find any better means of contacting you.
I would like to invite your community to write a review for an alternative Redis client library that is being proposed for inclusion in boost. As the author of a redis client yourself your opinion would be highly valuable. For more information see https://lists.boost.org/Archives/boost/2023/01/253871.php.
Thanks
目前测试是不会自动切换连接到其他节点,是有特殊的参数要设置吗?
support watch/multi/exec commands
could you give a demo with password and auth for redis cluster
场景描述:
集群模式下,设置密码。如果一个主节点异常,从节点转换为主节点。
调用构造函数时,节点信息传入的是原始的主节点信息。
此时循环尝试连接节点时,如果第一次连接到坏掉的节点,连接的异常信息会保存在errorinfo里面。
在第二次连接时,errorinfo信息被传入connect_redis_node()。上次失败的errorinfo信息没有被清空,会影响本次连接时的AUTH验证。 触发 NOAUTH Authentication required 的异常。
Do you have any example with connection pool?
Hi Will you be able to enable it for LSET, LPUSH ,LDEL, LRANGE...? Basically new sets of list command support.
Following code, always returns 1. What can be the issue?
const std::string& lua_scripts = r3c::format_string("local i=0; redis.call('HINCRBY',KEYS[1],ARGV[1],1); i= redis.call('HGET',KEYS[1],ARGV[1]); return i;");
std::vector<std::string> keys;
std::vector<std::string> parameters;
parameters.push_back("MYINSTANCE");
keys.push_back("NEXTINSTANCEID");
unsigned int myIDi=1;
const r3c::RedisReplyHelper redis_reply = rc.eval(lua_scripts,keys,parameters);
if (REDIS_REPLY_INTEGER == redis_reply->type)
myIDi= static_cast<int>(redis_reply->integer);
std::cout << myIDi << std::endl;
If I execute same in redis_cli, it works.
192.168.1.12:7050> eval "local i=0; redis.call('HINCRBY',KEYS[1],ARGV[1],1); i= redis.call('HGET',KEYS[1],ARGV[1]); return i;" 1 NEXTINSTANCEID MYINSTANCE
"16"
else if (REDIS_REPLY_INTEGER == redis_reply->type)
{
result = redis_reply->integer;
}
bool CRedisClient::hset(const std::string& key, const std::string& field, const std::string& value, std::pair<std::string, uint16_t>* which) throw (CRedisException)
{
struct ParamInfo param_info("HSET", sizeof("HSET")-1, &key, which);
param_info.str1 = &field;
param_info.str2 = &value;
int64_t result = redis_command(REDIS_REPLY_INTEGER, ¶m_info);
return result > 0;
}
When the value set by hset is written repeatedly, redis_reply-> integer returns the value 0.
so hset will return false.
当hset重复存入的value时, redis_reply-> integer 返回值是0。
会导致hset 函数中 关于 大于0的判断 返回 false。 这里是不是应该改为 >=0 ,或者 修改为 返回int类型
一天下来会有成千上万次这个错误,这个问题怎么解决呢?
如题。
在配置文件中配置了unixsocket,关闭了port。如何使用r3c连接redis服务器
unixsocket /tmp/redis.sock
unixsocketperm 777
在 1670 行 : CRedisClient::zrangebyscore 的实现中,
应该修改 const std::string str1 = any2string(min); const std::string str2 = any2string(max);
在 1692 行 : CRedisClient::zrevrangebyscore 的实现中,
应该修改 const std::string str1 = any2string(min); const std::string str2 = any2string(max);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.