csredis
csredis copied to clipboard
如何从redis里取BitArray
如下代码所示,我将一个BitArray存入redis中,成功了;但是在get的时候报错了。 var key = "love"; var bit = new BitArray(10000); RedisHelper.Instance.Set(key, bit); var cacehBit = RedisHelper.Instance.Get<BitArray>(key); 错误信息 Newtonsoft.Json.JsonSerializationException:“Cannot create and populate list type System.Collections.BitArray. Path '', line 1, position 1.”
存在redis的BitArray
期望的帮助
如何从redis中正确取出BitArray
本身有 setbit getbit 方法 http://redis.cn/commands/setbit.html
FreeRedis 是重新开发的 RedisClient :
https://github.com/2881099/FreeRedis
本身有 setbit getbit 方法 http://redis.cn/commands/setbit.html
FreeRedis 是重新开发的 RedisClient :
https://github.com/2881099/FreeRedis
不能直接使用setbit或getbit,我们是需要一口气从redis读出,要用setbit或getbit我们需要循环一个一个调用,效率不高。
byte[] value = cli.Get<byte[]>(key);
这样可以得到原型
byte[] 是转换的时候有问题吗?前后两次BitArray大小不一致了
这个byte[]不是BitArray,取决于存储时。
byte[] value = BitArray.ToByte(..) 假设有这个方法 cli.Set(key, value)
之后就可以Get<byte[]> 得到 value
