コード例 #1
0
 public RedisCommands(RedisBuffer redisBuffer)
 {
     this.redisBuffer = redisBuffer;
 }
コード例 #2
0
        /// <summary>
        /// Copy an ASCII string to byte array
        /// </summary>
        /// <param name="str">ASCII string to be copied</param>
        /// <param name="sourceIndex">Index on source string to start the copy</param>
        /// <param name="redisBuffer">The ProtocolBuffer to ASCII string to be copied</param>
        /// <param name="destinationIndex">Index on destination to start the copy</param>
        /// <param name="count">Count of ASCII chars to be copied from string</param>
        public static unsafe void ASCIICopyTo(this string str, int sourceIndex, RedisBuffer redisBuffer, int destinationIndex, int count)
        {
            fixed (char* pBytes = str)
            {
                var pSrc = pBytes;
                byte* pBuffer = redisBuffer.GetAddressFromIndex(destinationIndex);

                var pDest = pBuffer;
                var start = sourceIndex;
                var end = Math.Min(start + count, str.Length);
                // I would liked to evict this for loop
                for (var i = sourceIndex; i < end; i++)
                {
                    *pDest = (byte)*pSrc;
                    pDest++;
                    pSrc++;
                }

            }
        }
コード例 #3
0
 private static int BulkString(RedisBuffer redisBuffer, int i, params int[] words)
 {
     foreach (var word in words)
     {
         redisBuffer.WriteByte(TYPE_BULK_STRINGS, i);
         i++;
         i += word.DigitsCount().FastToArrayByte(redisBuffer, i);
         redisBuffer.CopyFrom(CRLF, 0, i, CRLFLength);
         i += CRLFLength;
         i += word.FastToArrayByte(redisBuffer, i);
         redisBuffer.CopyFrom(CRLF, 0, i, CRLFLength);
         i += CRLFLength;
     }
     return i;
 }
コード例 #4
0
 /// <summary>
 /// Preenche o buffer com os caracteres representando o valor inteiro e retorna o número de dígitos que foi preenchido no buffer
 /// </summary>
 /// <param name="value">Valor inteiro maior que zero que será convertido para string</param>
 /// <param name="redisBuffer">Array de caracteres que conterá a representação char do valor numérico</param>
 /// <param name="startIndex">Posição inicial no buffer onde os caracteres serão colocados</param>
 /// <returns>A quantidade de dígitos que foram escritas no array indicado por buffer</returns>
 public static int FastToArrayByte(this int value, RedisBuffer redisBuffer, int startIndex)
 {
     var digits = value.DigitsCount();
     startIndex += digits;
     while (value != 0)
     {
         var rem = value % 10;
         value /= 10;
         redisBuffer.WriteByte(CharsTable[rem], --startIndex);
     }
     return digits;
 }
コード例 #5
0
 private static int BulkString(RedisBuffer redisBuffer, int i, params byte[][] words)
 {
     foreach (var word in words)
     {
         redisBuffer.WriteByte(TYPE_BULK_STRINGS, i++);
         var wordLength = word.Length;
         i += wordLength.FastToArrayByte(redisBuffer, i);
         redisBuffer.CopyFrom(CRLF, 0, i, CRLFLength);
         i += CRLFLength;
         redisBuffer.CopyFrom(word, 0, i, wordLength);
         i += wordLength;
         redisBuffer.CopyFrom(CRLF, 0, i, CRLFLength);
         i += CRLFLength;
     }
     return i;
 }