Created
December 22, 2010 00:33
-
-
Save dchaplinsky/750885 to your computer and use it in GitHub Desktop.
Simple test of handlersocket and mysql python working together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from MySQLdb import connect | |
from pyhs.manager import Manager | |
from hashlib import md5 | |
from datetime import datetime | |
DB_NAME = 'simple_test' | |
DB_USER = 'root' | |
DB_PASSWORD = '' | |
TABLE_NAME = 'test_table' | |
connection = connect( | |
host = '', | |
user = DB_USER, | |
passwd = DB_PASSWORD, | |
db = DB_NAME, | |
use_unicode = True | |
) | |
cursor = connection.cursor() | |
cursor.execute('DROP TABLE IF EXISTS %s' % TABLE_NAME) | |
cursor.execute('CREATE TABLE `%s` (\ | |
`cache_key` varchar(255) NOT NULL PRIMARY KEY,\ | |
`value` longtext NOT NULL,\ | |
`expires` datetime NOT NULL\ | |
)' % TABLE_NAME) | |
manager = Manager( [('inet', 'localhost', 9998)], | |
[('inet', 'localhost', 9999)]) | |
for i in range(0, 10): | |
manager.insert( | |
DB_NAME, | |
TABLE_NAME, | |
[ ('cache_key', md5(str(i)).hexdigest()), | |
('value', md5(str(i) + 'foobar').hexdigest()), | |
('expires', str(datetime.now()))], | |
) | |
cursor.execute("SELECT count(*) FROM `%s`" % TABLE_NAME) | |
print cursor.fetchone() | |
# connection.rollback() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment