ServiceStack Redis客户端发生意外错误

时间:2017-04-17 12:09:09

标签: redis servicestack servicestack.redis

使用Servicestack操作Hashes时,会出现错误,并使用redisClientsManager。

这是我如何注册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>()));

以下是在Repository中使用它的方法,

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

//与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
}

错误:     意外错误:* 0 ....,Redis响应错误 关于如何使用PooledRedisClientManager Threadsafe的任何建议。!

添加堆栈跟踪:

消息:意外回复:* 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)      在\ Data \ Repository.cs中的Services.Data.Repository.GetMo(geoJ,DateTime,String):第169行      在Services.Api.getMService.Any(getM request)in \ Api \ getMService.cs:第15行      在lambda_method(Closure,Object,Object)      at ServiceStack.ServiceHost.ServiceRunner`1.Execute(IRequestContext requestContext,Object instance,TRequest request)

1 个答案:

答案 0 :(得分:3)

当您在调用LUA脚本时遇到Message:Unexpected reply错误时,您需要确保返回的脚本与您正在调用的RedisClient API匹配,在这种情况下RedisClient.ExecLuaShaAsString()需要string

如果您不确定LUA脚本返回什么类型,您可以调用更可重用的ExecLuaSha,它返回一个复杂的RedisText类型,可以支持许多不同的LUA响应类型。