1

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)

labilbe
  • 3,501
  • 2
  • 29
  • 34
Tech Cruize
  • 107
  • 1
  • 2
  • 16
  • Please provide an example of code that doesn't work, you can create a [Live C# Redis Example on Gistlyn](http://gistlyn.com/?gist=54e452bb1e86e132068a595d7e72d1a6). – mythz Apr 17 '17 at 14:14
  • @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 Apr 17 '17 at 17:36
  • 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 Apr 17 '17 at 17:38
  • @mythz i have updated my question with changes and Stack trace. But still getting the error.any leads would be very helpful. – Tech Cruize Apr 17 '17 at 18:43
  • 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 Apr 17 '17 at 18:47
  • @mythz Genius ..worked like charm ! – Tech Cruize Apr 17 '17 at 18:53
  • Glad to hear it! – mythz Apr 17 '17 at 18:57

1 Answers1

3

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.

mythz
  • 141,670
  • 29
  • 246
  • 390