Sequence is a class for atomically retrieving unique integer IDs using a key whose value stores the next ID as a piece of text. The first returned ID is 1.

ScalienDB is a key value store, so unique IDs have to be maintained in a separate key in a seperate table. For example:

people => 2500

In this case, the next sequence value returned would be 2500.

ScalienDB has a special ADD command which parses the value as a number and increments it by a user specified value. The Index class wraps this functionality, and increments the number by a user-defined gran (default 1000). This way, the server is contacted only every 1000th time the sequence is incremented, which is an important optimization since sending and waiting for commands to execute on the server is slow.

Note that if the client quits before using up all the sequence values retrieved by the last ADD command, those will not be passed out, and there will be a hole in the sequence.

Use Reset() to reset the sequence to 1. This sets:

key => 1

示例#1
0
        private void OpenDB()
        {
            try
            {
                db = clients[client_index].GetDatabase(dbname);
            }
            catch (SDBPException)
            {
                db = clients[client_index].CreateDatabase(dbname);
            }

            db = Utils.GetOrCreateEmptyDatabase(clients[client_index], dbname);

            try
            {
                indices = db.GetTable("indices");
            }
            catch (SDBPException)
            {
                indices = db.CreateTable("indices");
            }
            userIDs = indices.GetSequence("userIDs");

            try
            {
                table = db.GetTable(tablename);
            }
            catch (SDBPException)
            {
                table = db.CreateTable(tablename);
            }

            try
            {
                tableByNick = db.GetTable(tablename + "ByNick");
            }
            catch (SDBPException)
            {
                tableByNick = db.CreateTable(tablename + "ByNick");
            }

            try
            {
                tableByBirth = db.GetTable(tablename + "ByBirth");
            }
            catch (SDBPException)
            {
                tableByBirth = db.CreateTable(tablename + "ByBirth");
            }

            try
            {
                tableByLastLogin = db.GetTable(tablename + "ByLastLogin");
            }
            catch (SDBPException)
            {
                tableByLastLogin = db.CreateTable(tablename + "ByLastLogin");
            }
        }