Snippets
Small, reusable code snippets pulled straight from the articles.
Step 1: Establishing a Connection
From the post “What Happens When MySQL Executes a SELECT Query?”
mysql> show processlist;
+----+------+-----------+------+---------+------+-------+------+
| Id | User | Host | db | Command | Time | State | Info |
| 6 | root | localhost | NULL | Sleep | 736 | | NULL |
| 7 | root | localhost | NULL | Query | 0 | init | 0 |
+----+------+-----------+------+---------+------+-------+------+
2 rows in set (0.00 sec)Step 2: Parsing the SQL Syntax
From the post “What Happens When MySQL Executes a SELECT Query?”
mysql> select * form Member;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'form Member' at line 1Preprocessing Stage (Preprocessor)
From the post “What Happens When MySQL Executes a SELECT Query?”
mysql> select * from test;
ERROR 1146 (42S02): Table 'mysql.test' doesn't existWhat are the characteristics of variables, methods, and classes marked with the final keyword?
From the post “Top 10 Java Core Interview Questions”
final int x = 10;
// x cannot be reassignedWhat's the difference between override and overload?
From the post “Top 10 Java Core Interview Questions”
public class Example {
public void printInfo(String message) {
System.out.println("Message: " + message);
}
public void printInfo(int number) {
System.out.println("Number: " + number);
}
}Implementing a Distributed Lock with Redis
From the post “Distributed Locks and How to Implement Them with Redis”
func update() {
try {
// Try lock "key" with TTL = X seconds in Y seconds
if(tryLock(key, value, X, Y)) {
// Handle get, calculate and update resource
// Return
}
} finally {
unLock(key, value)
}
//
throw Exception("Try lock timeout")
}