Comments (11)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Awesome, closing.
Original comment by [email protected]
on 18 Jun 2010 at 6:30
- Changed state: Fixed
from servicestack.
Related Issues (20)
- Serializing byte[] cannot be Deserialized.
- CreateTransaction failing HOT 1
- TypeInitializationException when a class have a property that return an XElement value
- TypeInitializationException when deserialiaze a string to a class that have a static property
- Priority of Web Sockets HOT 1
- How to Store values in session
- Implement Forms Authentication Using ServiceStack HOT 1
- OrmPostgreSQL HOT 1
- Supporting for redis ZCOUNT command
- WCF helper implementation
- Null reference exception on call to GetAll HOT 2
- Broken link on Project Home HOT 2
- DeSerialising dictionary with type Dictionary<Tuple<string,string>,double>>() does not work
- Wrong Encoding
- ServiceStack.Redis reading large files from Redis server
- ServiceStack.Redis.RedisResponseException
- Db number is fogotten when using pooled clients.
- SOAP request and response wrappers
- Tutorial references ServiceStackHttpHandlerFactory which isn't included in ServiceStack.dll
- Future roadmap suggestion
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from servicestack.