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

RedisSessionStore - hkeys #1412

Closed
lvnar opened this issue Feb 9, 2016 · 9 comments
Closed

RedisSessionStore - hkeys #1412

lvnar opened this issue Feb 9, 2016 · 9 comments

Comments

@lvnar
Copy link

lvnar commented Feb 9, 2016

I cannot use de hkeys function on redis. There is an exception when I run it:

core.exception.AssertError@../.dub/packages/vibe-d-0.7.27/vibe-d/source/vibe/db/redis/redis.d(1150): Assertion failure
Program exited with code 1

Any idea?

@etcimon
Copy link
Contributor

etcimon commented Feb 9, 2016

That's because you used a RedisReply!T and didn't consume it completely in a previous connection. Make sure you do popFront() on each field until .front is null

@lvnar
Copy link
Author

lvnar commented Feb 10, 2016

I'm using popFront(), while(x.hasNext), but the error is still there when I try to use RedisReply again.

@etcimon
Copy link
Contributor

etcimon commented Feb 10, 2016

Do you have a code sample?

@lvnar
Copy link
Author

lvnar commented Feb 10, 2016

`auto scan = redisDB.keys(pattern);

while(scan.hasNext) {
keys ~= scan.front;
scan.popFront();
}
foreach (string key; keys) {
try {
keyValue = [key, redisDB.get(key)];
result ~= keyValue;
}
catch (Exception e){
auto res = redisDB.hgetAll(key);
while(res.hasNext){
res.popFront();
}
}
}`

There, on hgetAll is where the exception appears:

core.exception.AssertError@../.dub/packages/vibe-d-0.7.27/vibe-d/source/vibe/db/redis/redis.d(1150): Assertion failure

@etcimon
Copy link
Contributor

etcimon commented Feb 10, 2016

You should use foreach(key; scan) instead it's less error prone

@etcimon
Copy link
Contributor

etcimon commented Feb 10, 2016

The problem is that your first RedisReply from the keys call is still using the connection while you try to acquire the connection in a second RedisReply from the hgetAll call. You can simply enclose the first part in a scope like this:

{
   auto scan = redisDB.keys(pattern);

   while(scan.hasNext) {
      keys ~= scan.front;
      scan.popFront();
   }
}

@etcimon
Copy link
Contributor

etcimon commented Feb 10, 2016

You should avoid making calls that can throw inside catch clauses, and make sure you don't use try/catch as a replacement for if/else because it takes a while to populate a stack trace.

@s-ludwig
Copy link
Member

I've opened a fix (#1416), which is a slightly more refined version of the fix in #1396. It doesn't have a test case, yet. I'll add that before pulling.

s-ludwig added a commit that referenced this issue Feb 10, 2016
@lvnar
Copy link
Author

lvnar commented Feb 10, 2016

Thaks for the advices, were useful.

s-ludwig added a commit that referenced this issue Feb 11, 2016
s-ludwig added a commit that referenced this issue Feb 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants