Beispiel #1
0
        /// <summary>
        /// Get items from a database.
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="op"></param>
        /// <returns>false if not found.</returns>
        public bool Get <K, V>(ref K key, ref V value, CursorOp op)
        {
            ISerializer <K> keySerializer   = SerializerRegistry.Get <K>();
            ISerializer <V> valueSerializer = SerializerRegistry.Get <V>();

            byte[] keyBytes   = keySerializer.Serialize(key);
            byte[] valueBytes = valueSerializer.Serialize(value);

            bool found = Get(ref keyBytes, ref valueBytes, op);

            if (found)
            {
                if (keyBytes != null)
                {
                    key = keySerializer.Deserialize(keyBytes);
                }
                else
                {
                    key = default(K);
                }

                if (valueBytes != null)
                {
                    value = valueSerializer.Deserialize(valueBytes);
                }
                else
                {
                    value = default(V);
                }
            }
            return(found);
        }
Beispiel #2
0
        public void Put <K, V>(K key, V value, PutOption option = PutOption.Unspecific)
        {
            ISerializer <K> keySerializer   = SerializerRegistry.Get <K>();
            ISerializer <V> valueSerializer = SerializerRegistry.Get <V>();

            Put(keySerializer.Serialize(key), valueSerializer.Serialize(value), option);
        }
Beispiel #3
0
        /// <summary>
        /// Store by cursor.
        /// This function stores key/data pairs into the database. The cursor is
        /// positioned at the new item, or on failure usually near it.
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="option"></param>
        public void Put <K, V>(K key, V value, CursorPutOption option = CursorPutOption.Unspecific)
        {
            ISerializer <K> keySerializer   = SerializerRegistry.Get <K>();
            ISerializer <V> valueSerializer = SerializerRegistry.Get <V>();

            byte[] keyBytes   = keySerializer.Serialize(key);
            byte[] valueBytes = valueSerializer.Serialize(value);

            Put(keyBytes, valueBytes, option);
        }
Beispiel #4
0
        /// <summary>
        /// Get a single key
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public V Get <K, V>(K key)
        {
            ISerializer <K> keySerializer   = SerializerRegistry.Get <K>();
            ISerializer <V> valueSerializer = SerializerRegistry.Get <V>();

            byte[] buffer = Get(keySerializer.Serialize(key));
            if (buffer == null)
            {
                return(default(V));
            }
            return(valueSerializer.Deserialize(buffer));
        }
Beispiel #5
0
        /// <summary>
        /// Delete a specific key
        /// </summary>
        /// <param name="key"></param>
        /// <returns>true if deleted successfully; false means not-found</returns>
        public bool Del <K>(K key)
        {
            ISerializer <K> keySerializer = SerializerRegistry.Get <K>();

            return(Del(keySerializer.Serialize(key)));
        }