gregoriusxu / booksleeve

Automatically exported from code.google.com/p/booksleeve
Other
0 stars 0 forks source link

Incrementing a new field in a hash doesn't return '1' #28

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
var number= await Redis.Hashes.Increment(db, "key:, <int>);

The above line of code will return the new number stored in the field in that 
hash. If the field already exists this works just fine, but if it is a new 
field nothing is ever returned to the caller. I have hooked into the 
TaskScheduler.UnobservedException and no error is ever caught.

To clarify the data IS stored in redis just fine but control is never given 
back to me.

The documentation for Hashes.Increment says "If the field does not exists...the 
value will be set to zero before the operation"

In this scenario I would also except the method to return 1 since that would be 
the value.

Original issue reported on code.google.com by kaiser...@gmail.com on 20 Nov 2012 at 4:35

GoogleCodeExporter commented 8 years ago
I wanted to add that I am using the latest version available through nuget

Original comment by kaiser...@gmail.com on 20 Nov 2012 at 4:36

GoogleCodeExporter commented 8 years ago
k: will look, thanks

Original comment by marc.gravell on 20 Nov 2012 at 5:35

GoogleCodeExporter commented 8 years ago
Cannot reproduce - looks fine:

        [Test]
        public void TestIncrementOnHashThatDoesntExist()
        {
            using (var conn = Config.GetUnsecuredConnection())
            {
                conn.Keys.Remove(0, "keynotexist");
                var result = conn.Wait(conn.Hashes.Increment(0, "keynotexist", "fieldnotexist", 1));
                Assert.AreEqual(1, result);
            }
        }

are you sure you didn't simply forget to open the connection?

Original comment by marc.gravell on 21 Nov 2012 at 7:23

GoogleCodeExporter commented 8 years ago
also tested:

                conn.Keys.Remove(0, "keynotexist");
                var result1 = conn.Wait(conn.Hashes.Increment(0, "keynotexist", "fieldnotexist", 1));
                var result2 = conn.Wait(conn.Hashes.Increment(0, "keynotexist", "anotherfieldnotexist", 1));
                Assert.AreEqual(1, result1);
                Assert.AreEqual(1, result2);

Original comment by marc.gravell on 21 Nov 2012 at 7:30

GoogleCodeExporter commented 8 years ago
I am sure the conn is open because the data IS written to redis, I just never 
get anything back after the wait.  I'll see if I can repo it outside my app. If 
I can I'll attach the project

Original comment by kaiser...@gmail.com on 21 Nov 2012 at 4:45

GoogleCodeExporter commented 8 years ago
Any chance this is related to transactions in some way?

Original comment by marc.gravell on 21 Nov 2012 at 5:05

GoogleCodeExporter commented 8 years ago
Doubt it. I managed to reproduce it, and now that I am looking at it in 
isolation I think either I am missing something or I might have found a bug in 
the async stuff (or at least how I/booksleeve is using it).  

Check out the attached proj (you will need to restore the nugget paks... 32bit 
redis server/client included for ease) Click the button. you should see an 
alert with the value returned from redis. I can click it several times and 
nothing ever happens. As soon as I used the debugger to step into the call and 
follow the stack all the way to hashes.increment and back again it works. 

Everything may be fine from Booksleeves point of view, but why would this not 
be working until I step through it?

Let me know if you need clarification

Original comment by kaiser...@gmail.com on 21 Nov 2012 at 5:52

Attachments:

GoogleCodeExporter commented 8 years ago
Have you had a chance to look at this?

Original comment by kaiser...@gmail.com on 28 Nov 2012 at 8:54

GoogleCodeExporter commented 8 years ago
Sorry, first on my list for tomorrow morning. Promise!

Original comment by marc.gravell on 28 Nov 2012 at 9:08

GoogleCodeExporter commented 8 years ago
Nothing to do with BookSleeve; everything to do with MVC + async.

http://stackoverflow.com/questions/13621647/using-async-even-if-it-should-comple
te-as-part-of-a-mvc-route-deadlocks-the

Original comment by marc.gravell on 29 Nov 2012 at 8:30

GoogleCodeExporter commented 8 years ago
btw, the "quick fix" here is to have just:

        public Task<long> IncrementCount(string value)
        {
            return RedisManager.Connection.Hashes.Increment(db, "testkey", value);
        }

It is the addition of the async method that glitches it. I'm still interested 
to see if SO has any ideas...

Original comment by marc.gravell on 29 Nov 2012 at 9:04

GoogleCodeExporter commented 8 years ago
Various other options have been added on SO. Closing, unless you think I've 
missed anything.

Original comment by marc.gravell on 29 Nov 2012 at 9:30

GoogleCodeExporter commented 8 years ago
Awesome, thanks for your help.

Original comment by kaiser...@gmail.com on 29 Nov 2012 at 5:36