public void BitOpTest() { using (var mock = new MockConnector("MockHost", 9999, ":10\r\n", ":10\r\n", ":10\r\n", ":10\r\n")) using (var redis = new RedisClient(mock)) { Assert.AreEqual(10, redis.BitOp(RedisBitOp.And, "dest", "key1", "key2")); Assert.AreEqual("*5\r\n$5\r\nBITOP\r\n$3\r\nAND\r\n$4\r\ndest\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage()); Assert.AreEqual(10, redis.BitOp(RedisBitOp.Or, "dest", "key1", "key2")); Assert.AreEqual("*5\r\n$5\r\nBITOP\r\n$2\r\nOR\r\n$4\r\ndest\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage()); Assert.AreEqual(10, redis.BitOp(RedisBitOp.XOr, "dest", "key1", "key2")); Assert.AreEqual("*5\r\n$5\r\nBITOP\r\n$3\r\nXOR\r\n$4\r\ndest\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage()); Assert.AreEqual(10, redis.BitOp(RedisBitOp.Not, "dest", "key1", "key2")); Assert.AreEqual("*5\r\n$5\r\nBITOP\r\n$3\r\nNOT\r\n$4\r\ndest\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage()); } }
public void BitOpTest() { using (var mock = new FakeRedisSocket(":10\r\n", ":10\r\n", ":10\r\n", ":10\r\n")) using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999))) { Assert.Equal(10, redis.BitOp(RedisBitOp.And, "dest", "key1", "key2")); Assert.Equal("*5\r\n$5\r\nBITOP\r\n$3\r\nAND\r\n$4\r\ndest\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage()); Assert.Equal(10, redis.BitOp(RedisBitOp.Or, "dest", "key1", "key2")); Assert.Equal("*5\r\n$5\r\nBITOP\r\n$2\r\nOR\r\n$4\r\ndest\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage()); Assert.Equal(10, redis.BitOp(RedisBitOp.XOr, "dest", "key1", "key2")); Assert.Equal("*5\r\n$5\r\nBITOP\r\n$3\r\nXOR\r\n$4\r\ndest\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage()); Assert.Equal(10, redis.BitOp(RedisBitOp.Not, "dest", "key1", "key2")); Assert.Equal("*5\r\n$5\r\nBITOP\r\n$3\r\nNOT\r\n$4\r\ndest\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage()); } }
public void BitOpTest() { using (var mock = new FakeRedisSocket(":10\r\n", ":10\r\n", ":10\r\n", ":10\r\n")) using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999))) { Assert.AreEqual(10, redis.BitOp(RedisBitOp.And, "dest", "key1", "key2")); Assert.AreEqual("*5\r\n$5\r\nBITOP\r\n$3\r\nAND\r\n$4\r\ndest\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage()); Assert.AreEqual(10, redis.BitOp(RedisBitOp.Or, "dest", "key1", "key2")); Assert.AreEqual("*5\r\n$5\r\nBITOP\r\n$2\r\nOR\r\n$4\r\ndest\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage()); Assert.AreEqual(10, redis.BitOp(RedisBitOp.XOr, "dest", "key1", "key2")); Assert.AreEqual("*5\r\n$5\r\nBITOP\r\n$3\r\nXOR\r\n$4\r\ndest\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage()); Assert.AreEqual(10, redis.BitOp(RedisBitOp.Not, "dest", "key1", "key2")); Assert.AreEqual("*5\r\n$5\r\nBITOP\r\n$3\r\nNOT\r\n$4\r\ndest\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n", mock.GetMessage()); } }
public long StringBitOperation(string destinationKey, string firstKey, string secondKey, RedisBitwise bitwise = RedisBitwise.And) { if (bitwise.Equals(RedisBitwise.Not)) { return(database.BitOp(RedisBitOp.Not, destinationKey, firstKey, secondKey)); } if (bitwise.Equals(RedisBitwise.Or)) { return(database.BitOp(RedisBitOp.Or, destinationKey, firstKey, secondKey)); } if (bitwise.Equals(RedisBitwise.Xor)) { return(database.BitOp(RedisBitOp.XOr, destinationKey, firstKey, secondKey)); } return(database.BitOp(RedisBitOp.And, destinationKey, firstKey, secondKey)); }