Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redis.ttl fix for expired keys. + potential implementation of redis.zrangebyscore #141

Merged
merged 2 commits into from Dec 1, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions source/vibe/db/redis/redis.d
Expand Up @@ -151,8 +151,8 @@ final class RedisClient {

//TODO sort

size_t ttl(string key) {
return request!size_t("TTL", cast(ubyte[])key);
long ttl(string key) {
return request!long("TTL", cast(ubyte[])key);
}

string type(string key) {
Expand Down Expand Up @@ -432,7 +432,18 @@ final class RedisClient {
return request("ZRANGE", args);
}

//TODO: zrangeByScore
RedisReply zrangeByScore(string key, size_t start, size_t end, bool withScores=false) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential implementation, to be discussed

ubyte[][] args = [cast(ubyte[])key, cast(ubyte[])to!string(start), cast(ubyte[])to!string(end)];
if (withScores) args ~= cast(ubyte[])"WITHSCORES";
return request("ZRANGEBYSCORE", args);
}

RedisReply zrangeByScore(string key, size_t start, size_t end, size_t offset, size_t count, bool withScores=false) {
ubyte[][] args = [cast(ubyte[])key, cast(ubyte[])to!string(start), cast(ubyte[])to!string(end)];
if (withScores) args ~= cast(ubyte[])"WITHSCORES";
args ~= cast(ubyte[])"LIMIT" ~ cast(ubyte[])to!string(offset) ~ cast(ubyte[])to!string(count);
return request("ZRANGEBYSCORE", args);
}

int zrank(string key, string member) {
auto str = request!string("ZRANK", cast(ubyte[]) key, cast(ubyte[]) member);
Expand All @@ -447,7 +458,7 @@ final class RedisClient {
return request!size_t("ZREMRANGEBYRANK", cast(ubyte[])key, cast(ubyte[])to!string(start), cast(ubyte[])to!string(stop));
}

size_t zremRangeByScore(string key, double min, double max) {
size_t zremRangeByScore(string key, double min, double max) {
return request!size_t("ZREMRANGEBYSCORE", cast(ubyte[])key, cast(ubyte[])to!string(min), cast(ubyte[])to!string(max));
}

Expand Down