Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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()
Add Comment
Please, Sign In to add comment