本文整理汇总了Python中connection.Connection.get_conn方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.get_conn方法的具体用法?Python Connection.get_conn怎么用?Python Connection.get_conn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection.Connection
的用法示例。
在下文中一共展示了Connection.get_conn方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_from_list
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get_conn [as 别名]
def get_from_list(cls, list_name):
conn = Connection.get_conn()
objs = conn.lrange(list_name, 0, -1)
for obj_list in objs:
try:
yield [cls.load_from_str(obj_str) for obj_str in eval(obj_list)]
except:
pass
示例2: delete
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get_conn [as 别名]
def delete(cls, inst, del_inst = False, list_name = None):
if list_name is None:
list_name = inst.get_default_list_name()
conn = Connection.get_conn()
conn.hdel(list_name, inst.get_key())
if del_inst:
del inst
示例3: get_all
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get_conn [as 别名]
def get_all(cls, list_name = None):
if not cls.is_stored():
return
if list_name is None:
list_name = cls.get_default_list_name()
conn = Connection.get_conn()
hkeys = conn.hkeys(list_name)
for key in hkeys:
yield cls.load(key, list_name)
示例4: save
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get_conn [as 别名]
def save(self, list_name=None):
if not is_stored():
return
if list_name is None:
list_name = self.get_default_list_name()
self.list_name = list_name
storage_key = self.get_key()
conn = Connection.get_conn()
s = self.save_to_str()
conn.hset(list_name, storage_key, s)
示例5: add_to_list
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get_conn [as 别名]
def add_to_list(self, list_name):
conn = Connection.get_conn()
if conn.llen(list_name) > 0:
last_elem = eval(conn.lindex(list_name, -1))
if isinstance(last_elem, list):
if len(last_elem) > 0:
try:
last_set = ExercizeSet.load_from_str(last_elem[-1])
if last_set.exercize == self.exercize:
last_elem.append(self.save_to_str())
conn.lset(list_name, -1, last_elem)
return
except:
pass
conn.rpush(list_name, [self.save_to_str()])
示例6: load
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get_conn [as 别名]
def load(cls, key, list_name=None):
if not cls.is_stored():
return None
if list_name is None:
list_name = cls.get_default_list_name()
print "--- Loading '{0}' by key '{1}'".format(cls.__name__, key)
conn = Connection.get_conn()
str = conn.hget(list_name, key)
if str is None:
return None
obj = cls.load_from_str(str)
obj.set_key(key)
obj.list_name = list_name
return obj
示例7: any
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import get_conn [as 别名]
def any(day):
conn = Connection.get_conn()
return conn.llen('workout:' + date_to_str(day)) > 0