예제 #1
0
 public static bool Exists(Tx tx, byte[] key)
 {
     using (var cursor = tx.CreateCursor()) {
         var exists = cursor.MoveTo(key);
         return(exists);
     }
 }
예제 #2
0
        static IEnumerable <TOut> InternalScan <TOut>(Tx tx, byte[] key,
                                                      Func <Slice, byte[], TOut> convert, string traceName, int skip = 0)
        {
            tx.TraceStart(traceName);

            ushort x     = 0;
            var    slice = Slice.Create(key);
            var    range = FdbKeyRange.StartsWith(slice);

            using (var c = tx.CreateCursor()) {
                if (!c.MoveToFirstAfter(key))
                {
                    tx.TraceStop(traceName, x);
                    yield break;
                }

                var pair = c.Current;

                for (var i = 0; i < int.MaxValue; i++)
                {
                    var current = Slice.Create(pair.Key);
                    if (!range.Contains(current))
                    {
                        tx.TraceStop(traceName, x);
                        break;
                    }
                    if (i >= skip)
                    {
                        x += 1;
                        yield return(convert(current, pair.Value));
                    }

                    if (!c.MoveNext())
                    {
                        tx.TraceStop(traceName, x);
                        break;
                    }
                    pair = c.Current;
                }
            }
        }
예제 #3
0
        public static void DeleteRange(Tx tx, byte[] key, string traceName)
        {
            tx.TraceStart(traceName);
            ushort x     = 0;
            var    slice = Slice.Create(key);
            var    range = FdbKeyRange.StartsWith(slice);

            using (var c = tx.CreateCursor()) {
                if (!c.MoveToFirstAfter(key))
                {
                    tx.TraceStop(traceName, x);
                    return;
                }

                var pair = c.Current;

                for (var i = 0; i < int.MaxValue; i++)
                {
                    var current = Slice.Create(pair.Key);
                    if (!range.Contains(current))
                    {
                        tx.TraceStop(traceName, x);
                        break;
                    }

                    x += 1;
                    tx.Delete(pair.Key);

                    if (!c.MoveNext())
                    {
                        tx.TraceStop(traceName, x);
                        break;
                    }
                    pair = c.Current;
                }
            }


            tx.TraceStop(traceName);
        }