Ejemplo n.º 1
0
        public async Task Hash()
        {
            var hash = new RedisHash <string>(GlobalSettings.Default, "hash");
            await hash.Delete();

            await hash.Set("foo", 100);

            await hash.Set("bar", "aiueo!");

            (await hash.Get <int>("foo")).Value.Is(100);
            (await hash.Get <string>("bar")).Value.Is("aiueo!");
        }
Ejemplo n.º 2
0
        public async Task HashIncrMax()
        {
            var v = new RedisHash(settings, "test-hash");

            await v.Set("a", 0);

            (await v.IncrementLimitByMax("a", 10, 100)).Is(10);
            (await v.IncrementLimitByMax("a", 20, 100)).Is(30);
            (await v.IncrementLimitByMax("a", 30, 100)).Is(60);
            (await v.IncrementLimitByMax("a", 40, 100)).Is(100);
            (await v.IncrementLimitByMax("a", 50, 100)).Is(100);

            (await v.Get <long>("a")).Is(100);

            var v2 = new RedisHash(settings, "test-hash");
            await v2.Set("a", 0);

            (await v2.IncrementLimitByMax("a", 10.5, 100)).Is(10.5);
            (await v2.IncrementLimitByMax("a", 20.5, 100)).Is(31);
            (await v2.IncrementLimitByMax("a", 40.5, 100)).Is(71.5);
            (await v2.IncrementLimitByMax("a", 40.5, 100.1)).Is(100.1);
            (await v2.IncrementLimitByMax("a", 50.0, 100)).Is(100);

            (await v2.Get <double>("a")).Is(100);
        }
Ejemplo n.º 3
0
        public static Player Login(string login, string password)
        {
            if (!LoginDao.LoginExists(login))
            {
                throw new AccountError(AccountErrorCode.USER_OR_PASSWORD_INVALID, "Invalid username or password");
            }
            string userId = LoginDao.GetUserId(login);
            var    u      = RedisHash <Player> .Get(userId);

            if ((string)u.Password != password)
            {
                throw new AccountError(AccountErrorCode.USER_OR_PASSWORD_INVALID, "Invalid username or password");
            }
            Session session = new Session()
            {
                PlayerUid   = u.UserId,
                SessionUid  = Guid.NewGuid().ToString(),
                DateStarted = DateTime.Now.ToString()
            };

            u.SessionId = session.SessionUid;
            RedisHash <Session> .Set(session);

            RedisHash <Player> .Set(u);

            return(u);
        }
Ejemplo n.º 4
0
    public void TestPlayerDaoSaveRead()
    {
        var player = new Player();

        player.UserId   = "123";
        player.Login    = "******";
        player.Password = "******";

        RedisHash <Player> .Set(player);

        var user = RedisHash <Player> .Get("123");

        Assert.AreEqual(user.Login, player.Login);
        Assert.AreEqual(user.Password, player.Password);
    }
Ejemplo n.º 5
0
    public void TestUpdatingPosition()
    {
        var player = new Player();

        player.UserId   = "123";
        player.Login    = "******";
        player.Password = "******";
        player.X        = 1;
        player.Y        = 2;

        RedisHash <Player> .Set(player);

        PlayerService.UpdatePlayerPosition(player, 3, 4);

        var obtainedPlayer = RedisHash <Player> .Get("123");

        Assert.AreEqual(obtainedPlayer.X, 3);
        Assert.AreEqual(obtainedPlayer.Y, 4);
    }
Ejemplo n.º 6
0
        public static Player RegisterAccount(string login, string password, string email, Player playerTemplate)
        {
            var account = LoginDao.GetUserId(login);

            if (account != null)
            {
                throw new AccountError(AccountErrorCode.ACCOUNT_ALREADY_EXISTS, "Login already registered");
            }

            playerTemplate.Login    = login;
            playerTemplate.Password = password;
            playerTemplate.Email    = email;
            playerTemplate.UserId   = Guid.NewGuid().ToString();

            LoginDao.SetUserId(login, playerTemplate.UserId);
            RedisHash <Player> .Set(playerTemplate);

            return(playerTemplate);
        }
Ejemplo n.º 7
0
        public async Task HashDecrMin()
        {
            var v = new RedisHash(settings, "test-hash");

            await v.Set("a", 100);

            (await v.IncrementLimitByMin("a", -10, 0)).Is(90);
            (await v.IncrementLimitByMin("a", -20, 0)).Is(70);
            (await v.IncrementLimitByMin("a", -30, 0)).Is(40);
            (await v.IncrementLimitByMin("a", -42, 0)).Is(0);
            (await v.IncrementLimitByMin("a", -50, 0)).Is(0);

            (await v.Get <long>("a")).Is(0);

            var v2 = new RedisHash(settings, "test-hash");
            await v2.Set("a", 100);

            (await v2.IncrementLimitByMin("a", -10.5, 0.5)).Is(89.5);
            (await v2.IncrementLimitByMin("a", -20.5, 0.5)).Is(69);
            (await v2.IncrementLimitByMin("a", -40.5, 0.5)).Is(28.5);
            (await v2.IncrementLimitByMin("a", -40.5, 0.5)).Is(0.5);

            (await v2.Get <double>("a")).Is(0.5);
        }
Ejemplo n.º 8
0
        public async Task Hash()
        {
            var hash = new RedisHash<string>(GlobalSettings.Default, "hash");
            await hash.Delete();

            await hash.Set("foo", 100);
            await hash.Set("bar", "aiueo!");

            (await hash.Get<int>("foo")).Value.Is(100);
            (await hash.Get<string>("bar")).Value.Is("aiueo!");
        }
Ejemplo n.º 9
0
        public async Task HashDecrMin()
        {
            var v = new RedisHash(settings, "test-hash");

            await v.Set("a", 100);
            (await v.IncrementLimitByMin("a", -10, 0)).Is(90);
            (await v.IncrementLimitByMin("a", -20, 0)).Is(70);
            (await v.IncrementLimitByMin("a", -30, 0)).Is(40);
            (await v.IncrementLimitByMin("a", -42, 0)).Is(0);
            (await v.IncrementLimitByMin("a", -50, 0)).Is(0);

            (await v.Get<long>("a")).Is(0);

            var v2 = new RedisHash(settings, "test-hash");
            await v2.Set("a", 100);
            (await v2.IncrementLimitByMin("a", -10.5, 0.5)).Is(89.5);
            (await v2.IncrementLimitByMin("a", -20.5, 0.5)).Is(69);
            (await v2.IncrementLimitByMin("a", -40.5, 0.5)).Is(28.5);
            (await v2.IncrementLimitByMin("a", -40.5, 0.5)).Is(0.5);

            (await v2.Get<double>("a")).Is(0.5);
        }
Ejemplo n.º 10
0
        public async Task HashIncrMax()
        {
            var v = new RedisHash(settings, "test-hash");

            await v.Set("a", 0);
            (await v.IncrementLimitByMax("a", 10, 100)).Is(10);
            (await v.IncrementLimitByMax("a", 20, 100)).Is(30);
            (await v.IncrementLimitByMax("a", 30, 100)).Is(60);
            (await v.IncrementLimitByMax("a", 40, 100)).Is(100);
            (await v.IncrementLimitByMax("a", 50, 100)).Is(100);

            (await v.Get<long>("a")).Is(100);

            var v2 = new RedisHash(settings, "test-hash");
            await v2.Set("a", 0);
            (await v2.IncrementLimitByMax("a", 10.5, 100)).Is(10.5);
            (await v2.IncrementLimitByMax("a", 20.5, 100)).Is(31);
            (await v2.IncrementLimitByMax("a", 40.5, 100)).Is(71.5);
            (await v2.IncrementLimitByMax("a", 40.5, 100.1)).Is(100.1);
            (await v2.IncrementLimitByMax("a", 50.0, 100)).Is(100);

            (await v2.Get<double>("a")).Is(100);
        }