Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6060903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:52:40+00:00 2026-05-23T08:52:40+00:00

I use the RedisConnection Set method to set the byte array but how do

  • 0

I use the RedisConnection Set method to set the byte array but how do i get the data? The get returns a wrapped byte array?

Links:

  • http://code.google.com/p/booksleeve/
  • http://code.google.com/p/protobuf-net/

This works but it doesn’t feel right:

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));

            }
        }
    }
}

More info:

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());
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:52:40+00:00Added an answer on May 23, 2026 at 8:52 am

    That is entirely correct. “Get” (BookSleeve) returns a deferred byte[]. You have correctly used Wait to get the actual byte[], then used a MemoryStream over this byte[] to call Deserialize via protobuf-net.

    All good.

    If you make it clear any steps that you find ugly, I might be able to be more specific, but:

    • BookSleeve is entirely async via Task, hence the need for either Wait or ContinueWith to access the byte[]
    • protobuf-net is entirely Stream-based, hence the need for MemoryStream to sit on top of a byte[]

    Of course, if you add a generic utility method (maybe an extension method) you only need to write it once.

    And with the addition if a wrapper class (for some tracking/sliding-expiry) and a L1 cache (Redis as L2), this is pretty much exacty how we use it at stackoverflow.

    One note: the connection is thread safe and intended to be massively shared; don’t do a connection per operation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

use LWP::Simple; use Parallel::ForkManager; @links=( [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.1-windows.exe,SweetHome3D-2.1-windows.exe], [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.1-macosx.dmg,SweetHome3D-2.1-macosx.dmg], [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3DViewer-2.1.zip,SweetHome3DViewer-2.1.zip], ); # Max 30 processes for
Use case: we have some project meta-data files which we want tracked, but are
use ThreadPool.QueueUserWorkItem (WaitCallback, Object) to start a thread with my target method and data.
use a reapeter to display data, but sometimes the data is to big to
use this website a lot but first time posting. My program creates a number
We use a data acquisition card to take readings from a device that increases
USE [Fk_Test2] GO /****** Object: Table [dbo].[Owners] Script Date: 08/20/2010 16:52:44 ******/ SET ANSI_NULLS
Use of rails 3 recaptcha. In view _form.html.erb insert <%= recaptcha_tags %> But when
use Data::Dumper; %hash = ( Key => {test => [[testvalue, 10], [testvalue, 20]]}, Key2
use javascript or other method ? have any recommendation?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.