Skip to content

Commit

Permalink
after rebase & format
Browse files Browse the repository at this point in the history
  • Loading branch information
DvirDukhan committed Dec 3, 2020
1 parent 85cb8c6 commit 4f0b31b
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions src/libtorch_c/torch_extensions/torch_redis_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,40 @@
#include "torch/custom_class.h"
#include "../../redismodule.h"



struct RedisValue: torch::CustomClassHolder {
private:
struct RedisValue : torch::CustomClassHolder {
private:
union {
int intValue;
std::string stringValue;
std::vector<RedisValue*> arrayValue;
std::vector<RedisValue *> arrayValue;
};
public:

public:
RedisValue(RedisModuleCallReply *reply) {
if(RedisModule_CallReplyType(reply) == REDISMODULE_REPLY_ARRAY) {
size_t len = RedisModule_CallReplyLength(reply);
for(auto i = 0 ; i < len ; ++i){
RedisModuleCallReply *subReply = RedisModule_CallReplyArrayElement(reply, i);
RedisValue value(subReply);
arrayValue.push_back(value);
if (RedisModule_CallReplyType(reply) == REDISMODULE_REPLY_ARRAY) {
size_t len = RedisModule_CallReplyLength(reply);
for (auto i = 0; i < len; ++i) {
RedisModuleCallReply *subReply = RedisModule_CallReplyArrayElement(reply, i);
RedisValue value(subReply);
arrayValue.push_back(value);
}
}
}

if(RedisModule_CallReplyType(reply) == REDISMODULE_REPLY_STRING ||
RedisModule_CallReplyType(reply) == REDISMODULE_REPLY_ERROR){
size_t len;
const char* replyStr = RedisModule_CallReplyStringPtr(reply, &len);
PyObject* ret = PyUnicode_FromStringAndSize(replyStr, len);
if(!ret){
PyErr_Clear();
ret = PyByteArray_FromStringAndSize(replyStr, len);
if (RedisModule_CallReplyType(reply) == REDISMODULE_REPLY_STRING ||
RedisModule_CallReplyType(reply) == REDISMODULE_REPLY_ERROR) {
size_t len;
const char *replyStr = RedisModule_CallReplyStringPtr(reply, &len);
PyObject *ret = PyUnicode_FromStringAndSize(replyStr, len);
if (!ret) {
PyErr_Clear();
ret = PyByteArray_FromStringAndSize(replyStr, len);
}
return ret;
}
return ret;
}

if(RedisModule_CallReplyType(reply) == REDISMODULE_REPLY_INTEGER){
long long val = RedisModule_CallReplyInteger(reply);
return PyLong_FromLongLong(val);
}
if (RedisModule_CallReplyType(reply) == REDISMODULE_REPLY_INTEGER) {
long long val = RedisModule_CallReplyInteger(reply);
return PyLong_FromLongLong(val);
}
}

};

0 comments on commit 4f0b31b

Please sign in to comment.