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!"); }
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); }
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); }
public void TestPlayerMoving() { var client = ServerMocker.GetClient(); client.FullLoginSequence(_player); client.SendToServer(new EntityMovePacket() { From = new Position(_player.X, _player.Y), To = new Position(_player.X - 1, _player.Y), UID = _player.UserId }); var player = RedisHash <StoredPlayer> .Get(_player.UserId); Assert.That(player.X == _player.X - 1, "Server did not store that the player moved"); var onlinePlayer = Server.GetPlayer(_player.UserId); Assert.That(onlinePlayer.Position.X == _player.X - 1, "Server did not update online player position"); var chunk = onlinePlayer.GetChunk(); Assert.That(chunk.x == -1, "Player should have moved to other chunk"); Assert.That(chunk.PlayersInChunk.Contains(onlinePlayer), "New chunk did not contain the player reference"); }
public static bool ValidSession(string sessionId) { // var key = RedisHash<Session>.GetKeyNameFromType(sessionId); // var haveSession = Redis.Db.KeyExists(key); // if (!haveSession) // return false; var session = RedisHash <Session> .Get(sessionId); if (session == null) { return(false); } return(true); }
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); }
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); }
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); }
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!"); }
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); }
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); }