Giter VIP home page Giter VIP logo

Comments (11)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024
        public IDictionary<string, int> HarvestRedis(IRedisClient redis, DateTime date)
        {
                var keys = redis.SearchKeys("foo*");
                if (keys.Count > 0)
                {
                    var dict = new Dictionary<string, int>();


                    using(var transaction = redis.CreateTransaction())
                    {
                        foreach(var key in keys)
                        {
                            var y = key;
                            transaction.QueueCommand(x => x.IncrementValueBy(y,0), val=>dict.Add(y, val));
                        }
                        transaction.Commit();
                    }

                    return dict;
                }
                return new Dictionary<string, int>();
        }

works how i want it to

Original comment by [email protected] on 17 Jun 2010 at 7:24

from servicestack.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024
Hi Brian,

Unfortunately the way RedisTransaction works is that the callbacks are not 
processed until the transaction is committed. So if you want access to the 
return values you will need to provide callbacks. 

Your first code example is a little strange as there is no where are you 
populating the dictionary. 
Try adding a callback like so:

public IDictionary<string, int> HarvestRedis(IRedisClient redis, DateTime date)
{
    var keys = redis.SearchKeys("foo*");
    if (keys.Count > 0)
    {
        var dict = new Dictionary<string, int>();
        using(var transaction = redis.CreateTransaction())
        {
        foreach(var key in keys)
        {
            var y = key;
            transaction.QueueCommand(x => x.Get<int>(y), v => dict[key] = v);
        }
        transaction.Commit(); //Callbacks are processed here
        }
        return dict;
    }
    return new Dictionary<string, int>();
}

Note: Since the sample is not complete I haven't been able to test it but it 
should work. Also note there are batch requests for a lot of redis 
datastructures like 'redis.GetValues(keys)' which are atomic operations 
themselves and in this case would be more efficient then using a transaction.

Let me know if the above is helpful in solving your problem.

Cheers,
Demis

Original comment by [email protected] on 17 Jun 2010 at 9:30

from servicestack.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024
right, sorry about the bad first sample.

this sample doesn't work. the reason i'm doing this is because we need to 
atomically remove the keys after we get their values. I wanted to use 
redis.GetValues inside of the transaction, but the transaction doesn't have an 
overload i could figure out on it. the only thing that allows me to get values 
and then delete them is incrementing by 0. the first sample doesn't seem to hit 
any of the callbacks, the second sample throws a null-reference exception. 

        public IDictionary<string, int> HarvestRedis(IRedisClient redis, DateTime date)
        {
                var keys = redis.SearchKeys("foo*");
                if (keys.Count > 0)
                {
                    var dict = new Dictionary<string, int>();


                    using(var transaction = redis.CreateTransaction())
                    {
                        foreach(var key in keys)
                        {
                            var y = key;
                            transaction.QueueCommand(x => x.Get<int>(y), val=>dict.Add(y, val));
                        }
                        //transaction.QueueCommand(x => x.RemoveAll(keys));
                        transaction.Commit();
                    }

                    return dict;
                }
                return new Dictionary<string, int>();
        }

        public IList<string> HarvestRedis(IRedisClient redis, DateTime date)
        {
                var keys = redis.SearchKeys("foo*");
                if (keys.Count > 0)
                {
                    var values = new List<string>();

                    using(var transaction = redis.CreateTransaction())
                    {
                        transaction.QueueCommand(x => x.GetValues(keys), val => values = val);
                        //transaction.QueueCommand(x => x.RemoveAll(keys));
                        transaction.Commit();
                    }

                    return values;
                }
                return new List<string>();
        }

Original comment by [email protected] on 17 Jun 2010 at 9:54

from servicestack.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024
Hi Brian,

Sorry I was late resolving this issue, I was a little swamped yesterday fixing 
another issue with ServiceStack. 
Anyway happy to report that I've re-factored your above sample and included 
them as part of the test-suite which you can see here:
http://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Re
dis/ServiceStack.Redis.Tests/Issues/TransactionIssueTests.cs

I've added a couple of fixes to the client so now both tests pass! Basically a 
result of a couple of oversights that more regression testing would've picked 
up.

Anyway, the fix is available in v1.34 of the ServiceStack or Redis binaries the 
latter of which you can get here:
http://servicestack.googlecode.com/files/ServiceStack.Redis.zip

Let me know if it fixes your problem so I can close this ticket.

Cheers,
Demis

Original comment by [email protected] on 18 Jun 2010 at 10:15

from servicestack.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024
i'm using the GetValues method to load out the keys with the new binaries and 
am still seeing the same null reference exception. also tried the Get method, 
still no values.

Original comment by [email protected] on 18 Jun 2010 at 4:05

from servicestack.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024
Well that's the expected result after I uploaded the older version of the Redis 
Client instead of the new build :)

I've tried again, so the new version should be up now!
http://servicestack.googlecode.com/files/ServiceStack.Redis.zip

Original comment by [email protected] on 18 Jun 2010 at 4:15

from servicestack.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024
Well that's the expected result after I uploaded the older version of the Redis 
Client instead of the new build :)

I've tried again, so the new version should be up now!
http://servicestack.googlecode.com/files/ServiceStack.Redis.zip

Original comment by [email protected] on 18 Jun 2010 at 4:15

from servicestack.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024
the timestamp on the one you've uploaded is 6/2/2010. same results.

Original comment by [email protected] on 18 Jun 2010 at 4:46

from servicestack.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024
Actually, I'm having some problems uploading a new binary for some reason. 
Can you try again with file attached to this comment.

Original comment by [email protected] on 18 Jun 2010 at 4:49

Attachments:

from servicestack.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024
that does it. the Get code snippet i sent works now. thanks!

Original comment by [email protected] on 18 Jun 2010 at 4:52

from servicestack.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 21, 2024
Awesome, closing.

Original comment by [email protected] on 18 Jun 2010 at 6:30

  • Changed state: Fixed

from servicestack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.