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

Make the Redis high-level APIs safe. #2815

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
Changelog
=========

v0.10.2 - 2024-
v0.10.2 - 2025-
--------------------

### Features and improvements ###

- Adds a new `@viaStatus` REST parameter annotation for customizing the HTTP status - [pull #2806][issue2806]
- Adds a `MongoCollection.find` overload taking only a `FindOptions` parameter - [pull #2804][issue2804]
- Made the whole Redis API `@safe` - [pull #2815][issue2815]

### Bug fixes ###

- Fixes parsing plural-only translations in PO files and improves error messages - [pull #2805][issue2805]
- Fixed parsing plural-only translations in PO files and improves error messages - [pull #2805][issue2805]

[issue2804]: https://github.com/vibe-d/vibe.d/issues/2804
[issue2805]: https://github.com/vibe-d/vibe.d/issues/2805
[issue2806]: https://github.com/vibe-d/vibe.d/issues/2806
[issue2815]: https://github.com/vibe-d/vibe.d/issues/2815


v0.10.1 - 2024-09-07
Expand Down
4 changes: 2 additions & 2 deletions redis/vibe/db/redis/idioms.d
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct RedisCollection(T /*: RedisValue*/, RedisCollectionOptions OPTIONS = Redi
// TODO: add range queries
}

int opApply(int delegate(long id) del)
int opApply(int delegate(long id) @safe del)
{
static if (OPTIONS & RedisCollectionOptions.supportPaging) {
foreach (id; m_db.zrange!long(m_allSet, 0, -1))
Expand All @@ -100,7 +100,7 @@ struct RedisCollection(T /*: RedisValue*/, RedisCollectionOptions OPTIONS = Redi
return 0;
}

int opApply(int delegate(long id, T) del)
int opApply(int delegate(long id, T) @safe del)
{
static if (OPTIONS & RedisCollectionOptions.supportPaging) {
foreach (id; m_db.zrange!long(m_allSet, 0, -1))
Expand Down
9 changes: 5 additions & 4 deletions redis/vibe/db/redis/types.d
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ struct RedisValue {
string m_key;
}

@safe:
this(RedisDatabase db, string key) { m_db = db; m_key = key; }

/** The database in which the key is stored.
Expand Down Expand Up @@ -394,7 +395,7 @@ struct RedisHash(T = string) {
void opIndexOpAssign(string op)(T value, string field) if (op == "+") { m_db.hincr(m_key, field, value); }
void opIndexOpAssign(string op)(T value, string field) if (op == "-") { m_db.hincr(m_key, field, -value); }

int opApply(scope int delegate(string key, T value) del)
int opApply(scope int delegate(string key, T value) @safe del)
{
auto reply = m_db.hgetAll(m_key);
while (reply.hasNext()) {
Expand All @@ -407,7 +408,7 @@ struct RedisHash(T = string) {
}


int opApply(scope int delegate(string key) del)
int opApply(scope int delegate(string key) @safe del)
{
auto reply = m_db.hkeys(m_key);
while (reply.hasNext()) {
Expand Down Expand Up @@ -525,7 +526,7 @@ struct RedisList(T = string) {
Dollar opSub(long off) { return Dollar(offset - off); }
}

int opApply(scope int delegate(T) del)
int opApply(scope int delegate(T) @safe del)
{
foreach (v; this[0 .. $])
if (auto ret = del(v))
Expand Down Expand Up @@ -563,7 +564,7 @@ struct RedisSet(T = string) {
//long sinterStore(string destination, string[] keys...) { return request!long("SINTERSTORE", destination, keys); }
bool contains(T value) { return m_db.sisMember(m_key, value.toRedis()); }

int opApply(scope int delegate(T value) del)
int opApply(scope int delegate(T value) @safe del)
{
foreach (m; m_db.smembers!string(m_key))
if (auto ret = del(m.fromRedis!T()))
Expand Down
Loading