我试图为一个字节[] - > RedisValue转换为Strathweb.CacheOutput.WebApi2创建一个Redis提供程序, > byte []返回null。StackExchange.Redis将RedisValue转换为byte []通过“as byte []”返回null
我可以手动将对象类型设置为byte []而不是var/RedisValue,它将正确地将该值作为byte []返回,但是在将其设置为RedisValue后,其无法将其转换为字节[]。
他的接口有Get始终返回一个对象,所以我不能强制类型或使用单独的调用而不必修改接口。
如果我尝试做一个result as byte[]
我得到 Cannot convert type 'StackExchange.Redis.RedisValue' to 'byte[]' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
如果我尝试做一个(byte[])result
我得到Cannot cast 'result' (which has an actual type of 'StackExchange.Redis.RedisValue') to 'byte[]'
有我丢失的东西还是我将不得不破解它以某种方式通过检查基于密钥寻找哪种类型的数据?
这里的接口:
namespace WebApi.OutputCache.Core.Cache
{
public interface IApiOutputCache
{
void RemoveStartsWith(string key);
T Get<T>(string key) where T : class;
object Get(string key);
void Remove(string key);
bool Contains(string key);
void Add(string key, object o, DateTimeOffset expiration, string dependsOnKey = null);
IEnumerable<string> AllKeys { get; }
}
}
这里是其所谓的如何:
var val = _webApiCache.Get(cachekey) as byte[];
if (val == null) return;
编辑:API的实例添加我实现同时使用ServiceStack.Redis V3(因为它ATM工作只是使用object
和StackExchange.Redis不工作)
https://github.com/mackayj/WebApi.OutputCache.Redis.ServiceStack
https://github.com/mackayj/WebApi.OutputCache.Redis.StackExchange
问题是接口正在返回一个对象,调用代码正在做一个'as byte []'。我试图不修改接口或主代码,但我想我现在只是添加一个返回字节[]的新方法。我编辑我的帖子,显示正确的调用代码与'作为字节[]' – John 2014-10-03 17:43:40