我应该如何在protobuf-net中使用Booksleeve?

| 我使用RedisConnection Set方法设置字节数组,但是如何获取数据? get返回包装的字节数组吗? 链接: http://code.google.com/p/booksleeve/ http://code.google.com/p/protobuf-net/ 这可行,但感觉不正确:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BookSleeve;
using ProtoBuf;
using System.IO;
namespace RedisTest001
{
    [ProtoContract, Serializable]
    public class Price
    {
        private string _ticker;
        private double _value;

        public Price()
        {
        }

        public Price(string ticker, double value)
        {
            _ticker = ticker;
            _value = value;
        }


        [ProtoMember(1)]
        public string Ticker
        {
            get { return _ticker; }
            set { _ticker = value; }
        }

        [ProtoMember(2)]
        public double Value
        {
            get { return _value; }
            set { _value = value; }
        }


    }

    class Program
    {
        static void Main(string[] args)
        {
            using (var conn = new RedisConnection(\"localhost\"))
            {
                Price p = new Price(\"IBM\", 101.55);

                byte[] raw;
                using (MemoryStream ms = new MemoryStream())
                {
                    Serializer.Serialize<Price>(ms,p);
                    raw = ms.ToArray();
                }

                conn.Open();
                conn.Set(1, p.Ticker, raw);


                var tb  = conn.Get(1,\"IBM\");

                var str = conn.Wait(tb);

                 Price p2 = Serializer.Deserialize<Price>(new MemoryStream(str));

            }
        }
    }
}
更多信息:
public static class pex
{
    public static byte[] ToBArray<T>(this T o)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            Serializer.Serialize<T>(ms, o);
            return ms.ToArray();
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Random RandomClass = new Random();

        using (var conn = new RedisConnection(\"localhost\"))
        {

            conn.Open();

            for (int i = 0; i < 500000; i++)
            {
                Price p = new Price(\"IBM\", RandomClass.Next(0, 1000));
                conn.AddToSet(2, \"PRICE.IBM\", p.ToBArray());
            }
    
已邀请:
        那是完全正确的。 \“ Get \”(BookSleeve)返回延迟的
byte[]
。您已经正确地使用了Wait来获取实际的
byte[]
,然后在
byte[]
上使用
MemoryStream
通过protobuf-net调用
Deserialize
。 都好。 如果您弄清楚丑陋的任何步骤,我也许可以更具体一些,但是: BookSleeve通过ѭ7完全异步,因此需要ѭ8或ѭ9来访问ѭ2。 protobuf-net完全基于流,因此需要
MemoryStream
才能位于ѭ2top之上 当然,如果添加通用的实用程序方法(可能是扩展方法),则只需编写一次。 加上一个包装器类(用于某些跟踪/滑动过期)和一个L1缓存(Redis表示为L2),这在我们在stackoverflow上的使用方式非常准确。 需要注意的是:该连接是线程安全的,并且打算被大量共享;请勿在每次操作时进行连接。     

要回复问题请先登录注册