1
votes

Am getting an error while manipulating Hashes with Servicestack pooled redisClientsManager.

here is how i have registered the IOC

private static IRedisClientsManager redisClientsManager;
redisClientsManager =  new PooledRedisClientManager("host:6379");
container.Register<IRedisClientsManager>(c => redisClientsManager);
container.Register(c => c.Resolve<IRedisClientsManager>().GetClient());
container.Register<IRepository>(c => new Repository(c.Resolve<IRedisClientsManager>()));

And Here is how am using it in Repository,

IRedisClientsManager manager;
public repository(IRedisClientsManager mgr)
{
 this.manager=mgr;
}

//Method to talk to redis

using(var red = manager.getClient())
{
  //do stuff with Other datatype except Hashes WORKS
}
//Error raised here
using(var redHash = manager.getClient())
{
  //do stuff with Hashes DOESNT WORKS
}

Error: Unexpected Error:* 0...., Redis response Error Any Suggestions on how to use PooledRedisClientManager Threadsafe.!

Adding Stack trace :

Message:Unexpected reply: *0, sPort: 6379, LastCommand:

at ServiceStack.Redis.RedisNativeClient.CreateResponseError(String error) at ServiceStack.Redis.RedisNativeClient.ParseSingleLine(String r) at ServiceStack.Redis.RedisNativeClient.SendExpectData(Byte[][] cmdWithBinaryArgs) at ServiceStack.Redis.RedisNativeClient.EvalShaStr(String sha1, Int32 numberKeysInArgs, Byte[][] keys) at ServiceStack.Redis.RedisClient.ExecLuaShaAsString(String sha1, String[] keys, String[] args) at Services.Data.Repository.GetMo(geoJ , DateTime , String ) in \Data\Repository.cs:line 169 at Services.Api.getMService.Any(getM request) in \Api\getMService.cs:line 15 at lambda_method(Closure , Object , Object ) at ServiceStack.ServiceHost.ServiceRunner`1.Execute(IRequestContext requestContext, Object instance, TRequest request)

1
Please provide an example of code that doesn't work, you can create a Live C# Redis Example on Gistlyn. - mythz
@mythz I tried recreating the problem but was unable to reproduce. Am implementing Repository Pattern ,where i register Repository with constructor instantiated Clients Manager as shown above. - Tech Cruize
Right, but we'll need to be able to repro the issue in order to identify it. Everything looks ok except CacheClient should be a singleton (so remove ReuseScope.None) and GetClient() should be PascalCase. Also you don't need an array for new PooledRedisClientManager("host:6379") - mythz
@mythz i have updated my question with changes and Stack trace. But still getting the error.any leads would be very helpful. - Tech Cruize
This error is a result of calling ExecLuaShaAsString. Does your LUA code your Service is executing return a string? Maybe try calling ExecLuaSha which can support variable LUA response types. - mythz

1 Answers

3
votes

When you get an Message:Unexpected reply Error when calling a LUA script you need to ensure that what the script is returning matches with the RedisClient API you're calling, which in this case of RedisClient.ExecLuaShaAsString() expects a string.

If you're unsure of what Type your LUA script returns you can call the more reusable ExecLuaSha which returns a complex RedisText type that can support a number of different LUA response types.