本文整理匯總了Python中redis.client.Redis.flushdb方法的典型用法代碼示例。如果您正苦於以下問題:Python Redis.flushdb方法的具體用法?Python Redis.flushdb怎麽用?Python Redis.flushdb使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.client.Redis
的用法示例。
在下文中一共展示了Redis.flushdb方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from redis.client import Redis [as 別名]
# 或者: from redis.client.Redis import flushdb [as 別名]
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
logging.getLogger("c2corg_api").setLevel(logging.INFO)
redis_url = "{0}?db={1}".format(settings["redis.url"], settings["redis.db_cache"])
log.info("Cache Redis: {0}".format(redis_url))
# we don't really need a connection pool here, but the `from_url`
# function is convenient
redis_pool = ConnectionPool.from_url(redis_url, max_connections=1)
# remove all keys from the database
r = Redis(connection_pool=redis_pool)
r.flushdb()
log.info("Flushed cache")
示例2: main
# 需要導入模塊: from redis.client import Redis [as 別名]
# 或者: from redis.client.Redis import flushdb [as 別名]
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
logging.getLogger('c2corg_ui').setLevel(logging.INFO)
log.info('Cache Redis: {0}'.format(settings['redis.url']))
# we don't really need a connection pool here, but the `from_url`
# function is convenient
redis_pool = ConnectionPool.from_url(
settings['redis.url'], max_connections=1)
# remove all keys from the database
r = Redis(connection_pool=redis_pool)
r.flushdb()
log.info('Flushed cache')
示例3: BaseTest
# 需要導入模塊: from redis.client import Redis [as 別名]
# 或者: from redis.client.Redis import flushdb [as 別名]
class BaseTest(ZTest):
def setUp(self):
self.redis = Redis()
self.redis.flushdb()
self.model = TModel(redis=self.redis)
示例4: RUnitTest
# 需要導入模塊: from redis.client import Redis [as 別名]
# 或者: from redis.client.Redis import flushdb [as 別名]
class RUnitTest(BaseTest):
def setUp(self):
self.redis = Redis()
self.redis.flushdb()
self.model = TestModel(self.redis)
def test_init(self):
self.assertTrue(isinstance(self.model.cursor, Cursor))
def test_incr(self):
global incr_value
model = ModelWithIncr(redis=self.redis)
self.assertEqual(model.incr_field.get(), 0)
model.incr_field += 1
self.assertEqual(model.incr_field.get(), 1)
incr_value = 13
model.incr_field += 11
self.assertEqual(model.incr_field.get(), 1 + 13 + 11)
model.incr_field.set(10)
self.assertEqual(model.incr_field.get(), 10)
def test_simple(self):
self.assertEqual(self.model.id.get(), None)
self.assertEqual(self.model.name.get(), None)
self.model.id.set(1)
self.assertEqual(self.model.id.get(), 1)
self.model.name.set('test_name')
self.model = TestModel(redis=self.redis)
self.assertEqual(self.model.id.get(), 1)
self.assertEqual(self.model.name.get(), 'test_name')
self.assertEqual(self.model.data(), {'id': 1, 'name': 'test_name'})
def test_data(self):
self.model.id.set(1)
self.model.name.set('test_name')
self.assertEqual(self.model.id.get(), 1)
self.assertEqual(self.model.name.get(), 'test_name')
self.assertEqual(self.model.data(), {'id': 1, 'name': 'test_name'})
def test_nested_model(self):
model = NestedModel(redis=self.redis)
self.assertEqual(len(model.fields()), 3)
model.nested.store.set(1)
self.assertEqual(model.nested.store.get(), 1)
self.assertDictEqual(model.data(), {'nested': {'store': 1},
'id': None, 'name': None})
def test_cross_model(self):
one, two = (NestedModel(prefix=1, redis=self.redis),
NestedModel(prefix=2, redis=self.redis))
self.assertEqual(one.cursor.key, '1')
self.assertEqual(two.cursor.key, '2')
one.id.set(1)
two.id.set(2)
self.assertEqual(one.id.get(), 1)
self.assertEqual(two.id.get(), 2)
self.assertEqual(one.nested.cursor.key, '1:nested')
self.assertEqual(two.nested.cursor.key, '2:nested')
one.nested.store.set(1)
two.nested.store.set(2)
self.assertNotEqual(one.nested.store, two.nested.store)
self.assertEqual(one.nested.store.get(), 1)
self.assertEqual(two.nested.store.get(), 2)
def test_defaults(self):
TestModel.defaults = {'id': 334, 'name': 'HELLO'}
self.assertEqual(self.model.id.get(), 334)
self.assertEqual(self.model.name.get(), 'HELLO')
TestModel.defaults = False
def test_session_remove(self):
session = self.model._session = RSession()
self.model.remove()
self.eq(session.changes(), {self.model.prefix: None})