Skip to content

Commit

Permalink
Use unsigned type for cursors (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler92 authored Jun 17, 2024
1 parent fe6e72f commit add50aa
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 253 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ redis.smembers("s1", std::back_inserter(s_vec));
##### SCAN Commands
```C++
auto cursor = 0LL;
sw::redis::Cursor cursor = 0;
auto pattern = "*pattern*";
auto count = 5;
std::unordered_set<std::string> keys;
Expand Down
16 changes: 8 additions & 8 deletions src/sw/redis++/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ void restore(Connection &connection,
bool replace);

inline void scan(Connection &connection,
long long cursor,
Cursor cursor,
const StringView &pattern,
long long count) {
connection.send("SCAN %lld MATCH %b COUNT %lld",
connection.send("SCAN %llu MATCH %b COUNT %lld",
cursor,
pattern.data(), pattern.size(),
count);
Expand Down Expand Up @@ -729,10 +729,10 @@ inline void hmset(Connection &connection,

inline void hscan(Connection &connection,
const StringView &key,
long long cursor,
Cursor cursor,
const StringView &pattern,
long long count) {
connection.send("HSCAN %b %lld MATCH %b COUNT %lld",
connection.send("HSCAN %b %llu MATCH %b COUNT %lld",
key.data(), key.size(),
cursor,
pattern.data(), pattern.size(),
Expand Down Expand Up @@ -937,10 +937,10 @@ inline void srem_range(Connection &connection,

inline void sscan(Connection &connection,
const StringView &key,
long long cursor,
Cursor cursor,
const StringView &pattern,
long long count) {
connection.send("SSCAN %b %lld MATCH %b COUNT %lld",
connection.send("SSCAN %b %llu MATCH %b COUNT %lld",
key.data(), key.size(),
cursor,
pattern.data(), pattern.size(),
Expand Down Expand Up @@ -1294,10 +1294,10 @@ inline void zrevrank(Connection &connection,

inline void zscan(Connection &connection,
const StringView &key,
long long cursor,
Cursor cursor,
const StringView &pattern,
long long count) {
connection.send("ZSCAN %b %lld MATCH %b COUNT %lld",
connection.send("ZSCAN %b %llu MATCH %b COUNT %lld",
key.data(), key.size(),
cursor,
pattern.data(), pattern.size(),
Expand Down
2 changes: 2 additions & 0 deletions src/sw/redis++/cxx17/sw/redis++/cxx_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ using Monostate = std::monostate;
template <typename F, typename ...Args>
using IsInvocable = std::is_invocable<F, Args...>;

using Cursor = unsigned long long;

}

}
Expand Down
32 changes: 16 additions & 16 deletions src/sw/redis++/queued_redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,22 +260,22 @@ class QueuedRedis {

// TODO: sort

QueuedRedis& scan(long long cursor,
QueuedRedis& scan(Cursor cursor,
const StringView &pattern,
long long count) {
return command(cmd::scan, cursor, pattern, count);
}

QueuedRedis& scan(long long cursor) {
QueuedRedis& scan(Cursor cursor) {
return scan(cursor, "*", 10);
}

QueuedRedis& scan(long long cursor,
QueuedRedis& scan(Cursor cursor,
const StringView &pattern) {
return scan(cursor, pattern, 10);
}

QueuedRedis& scan(long long cursor,
QueuedRedis& scan(Cursor cursor,
long long count) {
return scan(cursor, "*", count);
}
Expand Down Expand Up @@ -740,26 +740,26 @@ class QueuedRedis {
}

QueuedRedis& hscan(const StringView &key,
long long cursor,
Cursor cursor,
const StringView &pattern,
long long count) {
return command(cmd::hscan, key, cursor, pattern, count);
}

QueuedRedis& hscan(const StringView &key,
long long cursor,
Cursor cursor,
const StringView &pattern) {
return hscan(key, cursor, pattern, 10);
}

QueuedRedis& hscan(const StringView &key,
long long cursor,
Cursor cursor,
long long count) {
return hscan(key, cursor, "*", count);
}

QueuedRedis& hscan(const StringView &key,
long long cursor) {
Cursor cursor) {
return hscan(key, cursor, "*", 10);
}

Expand Down Expand Up @@ -930,26 +930,26 @@ class QueuedRedis {
}

QueuedRedis& sscan(const StringView &key,
long long cursor,
Cursor cursor,
const StringView &pattern,
long long count) {
return command(cmd::sscan, key, cursor, pattern, count);
}

QueuedRedis& sscan(const StringView &key,
long long cursor,
Cursor cursor,
const StringView &pattern) {
return sscan(key, cursor, pattern, 10);
}

QueuedRedis& sscan(const StringView &key,
long long cursor,
Cursor cursor,
long long count) {
return sscan(key, cursor, "*", count);
}

QueuedRedis& sscan(const StringView &key,
long long cursor) {
Cursor cursor) {
return sscan(key, cursor, "*", 10);
}

Expand Down Expand Up @@ -1250,26 +1250,26 @@ class QueuedRedis {
}

QueuedRedis& zscan(const StringView &key,
long long cursor,
Cursor cursor,
const StringView &pattern,
long long count) {
return command(cmd::zscan, key, cursor, pattern, count);
}

QueuedRedis& zscan(const StringView &key,
long long cursor,
Cursor cursor,
const StringView &pattern) {
return zscan(key, cursor, pattern, 10);
}

QueuedRedis& zscan(const StringView &key,
long long cursor,
Cursor cursor,
long long count) {
return zscan(key, cursor, "*", count);
}

QueuedRedis& zscan(const StringView &key,
long long cursor) {
Cursor cursor) {
return zscan(key, cursor, "*", 10);
}

Expand Down
Loading

0 comments on commit add50aa

Please sign in to comment.