Skip to content

Commit

Permalink
redis, bugfix: fix implement of `RedisSortedSet::add(OptArgs sms, int…
Browse files Browse the repository at this point in the history
…32_t& retVal)`. (#410)
  • Loading branch information
richardo2016 authored and xicilion committed Apr 21, 2018
1 parent fd8e4b7 commit c33150e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
15 changes: 15 additions & 0 deletions fibjs/include/Redis.h
Expand Up @@ -181,6 +181,21 @@ class Redis : public Redis_base {
return 0; return 0;
} }


template <typename T>
result_t add(std::vector<T>& args)
{
result_t hr;
int32_t i;

for (i = 0; i < args.size(); i++) {
hr = add(args[i]);
if (hr < 0)
return hr;
}

return 0;
}

result_t add(v8::Local<v8::Value> v) result_t add(v8::Local<v8::Value> v)
{ {
result_t hr; result_t hr;
Expand Down
13 changes: 8 additions & 5 deletions fibjs/src/db/redis/RedisSortedSet.cpp
Expand Up @@ -35,14 +35,17 @@ result_t RedisSortedSet::add(OptArgs sms, int32_t& retVal)
if (sms.Length() & 1) if (sms.Length() & 1)
return CHECK_ERROR(CALL_E_INVALIDARG); return CHECK_ERROR(CALL_E_INVALIDARG);


std::vector<v8::Local<v8::Value>> mss;
sms.GetData(mss);

int32_t i; int32_t i;
for (i = 0; i < sms.Length(); i += 2) { for (i = 0; i < mss.size(); i += 2) {
v8::Local<v8::Value> v = sms[i]; v8::Local<v8::Value> v = mss[i];
sms[i] = sms[i + 1]; mss[i] = mss[i + 1];
sms[i + 1] = v; mss[i + 1] = v;
} }


return m_rdb->doCommand("ZADD", m_key, sms, retVal); return m_rdb->doCommand("ZADD", m_key, mss, retVal);
} }


result_t RedisSortedSet::score(Buffer_base* member, obj_ptr<Buffer_base>& retVal) result_t RedisSortedSet::score(Buffer_base* member, obj_ptr<Buffer_base>& retVal)
Expand Down

0 comments on commit c33150e

Please sign in to comment.