def test_mul(self): a = ["wagwaan", "hot", "skull"] b = hot_redis.List(a) i = 9000 self.assertEquals(a * i, hot_redis.List(a) * i) b *= i self.assertEquals(a * i, b)
def test_transaction(self): with_transaction = hot_redis.List([1]) without_transaction = hot_redis.List(key=with_transaction.key, client=hot_redis.HotClient()) with hot_redis.transaction(): with_transaction.append(1) self.assertEqual(len(without_transaction), 1) self.assertEqual(len(without_transaction), 2)
def test_add(self): a = ["wagwaan", "hot", "skull"] b = ["nba", "hang", "time"] self.assertEquals(a + b, hot_redis.List(a) + hot_redis.List(b)) self.assertEquals(a + b, hot_redis.List(a) + b) c = hot_redis.List(a) d = hot_redis.List(b) d += c c += b self.assertEquals(a + b, c) self.assertEquals(b + a, d)
def test_del(self): a = ["wagwaan", "hot", "skull"] b = hot_redis.List(a) del a[1] self.assertNotEquals(a, b) del b[1] self.assertEquals(a, b)
def __init__(self, var, val): if type(val) == dict: # print('dict') instance = hot_redis.Dict(val, key=var) elif type(val) == list: # print('list') instance = hot_redis.List(val, key=var) elif type(val) == set: # print('set') instance = hot_redis.Set(val, key=var) elif type(val) == str: # print('str') instance = hot_redis.String(val, key=var) elif type(val) == int: # print('int') instance = hot_redis.Int(val, key=var) elif type(val) == None: # Not handled # print('None Not handled') return None elif callable(val): # print('function') return None else: # print("else, None:", type(val)) return None # instance = hot_redis(instance) # print("debug: ", var, val) self.instance = instance
def test_insert(self): a = ["wagwaan", "hot", "skull"] b = hot_redis.List(a) i = "popcaan" a.insert(1, i) b.insert(1, i) self.assertEquals(a, b)
def test_append(self): a = ["wagwaan", "hot", "skull"] b = hot_redis.List(a) i = "popcaan" a.append(i) b.append(i) self.assertEquals(a, b)
def test_extend(self): a = ["wagwaan", "hot", "skull"] b = ["nba", "hang", "time"] c = hot_redis.List(a) a.extend(b) c.extend(b) self.assertEquals(a, c)
def test_get(self): a = ["wagwaan", "hot", "skull"] * 10 b = hot_redis.List(a) self.assertEquals(a[4], b[4]) self.assertEquals(a[3:12], b[3:12]) self.assertEquals(a[:-5], b[:-5]) self.assertRaises(IndexError, lambda: b[len(b)])
def test_set(self): a = ["wagwaan", "hot", "skull"] b = hot_redis.List(a) i = "popcaan" a[1] = i self.assertNotEquals(a, b) b[1] = i self.assertEquals(a, b)
def test_sort(self): a = ["wagwaan", "hot", "skull"] * 10 b = hot_redis.List(a) a.sort() b.sort() self.assertEquals(a, b) a.sort(reverse=True) b.sort(reverse=True) self.assertEquals(a, b)
def __init__(self, user='', doc=''): self.key = md5(str(MAIN_PPS) + doc + PPS_STRUCT).hexdigest() self.key_pos_tags = md5(str(MAIN_PPS) + doc + POS_TAGS).hexdigest() self.key_map_persistent = md5(str(MAIN_PPS) + doc + PERSIST).hexdigest() self.pps = hot_redis.Dict(key=self.key, client=client) self.tags = hot_redis.List(key=self.key_pos_tags, client=client) self.persist = hot_redis.Dict(key=self.key_map_persistent, client=client) self.user_list = UserOrder(doc=doc) self.user = user if hot_redis.List(key=KEYS, client=client).count(self.key) == 0: self.pps['0'] = PHI # unicode for null self.pps['1'] = PHI # unicode for null self.persist['0'] = YES self.persist['1'] = YES self.tags.append('0') self.tags.append('1') hot_redis.List(key=KEYS, client=client).append(self.key)
def test_pop(self): a = ["wagwaan", "hot", "skull"] * 10 b = hot_redis.List(a) a.pop() b.pop() self.assertEquals(a, b) a.pop(0) b.pop(0) self.assertEquals(a, b) a.pop(-1) b.pop(-1) self.assertEquals(a, b) a.pop(20) b.pop(20) self.assertEquals(a, b)
def hot_redis_test(clear=False): """ 测试 hot redis 常用功能 :return: """ # clear = True dat = { 'base': 10, 'crx': 2, 'jobbole': 1, } # 初始化一个字典 _dict = hot_redis.Dict(client=rdb_out, key='ig.dict') # 更新, 自动写入 redis _dict['fns'] = dat # 删除字典 if clear: _dict.clear() # 测试 list _list = hot_redis.List(client=rdb_out, key='ig.list') _list += list(dat.keys()) # pop list if clear: for i in range(len(_list)): _list.pop() # 字符串 _string = hot_redis.String(client=rdb_out, key='ig.string', initial=','.join([str(_) for _ in dat.keys()])) # 没有找到 hot_redis 如何删除, 只好使用 redis 默认的 if clear: rd.delete('ig.string')
def test_reverse(self): a = ["wagwaan", "hot", "skull"] b = hot_redis.List(a) a.reverse() b.reverse() self.assertEquals(a, b)
def test_len(self): a = ["wagwaan", "hot", "skull"] b = hot_redis.List(a) self.assertEquals(len(a), len(b))
def test_initial(self): a = ["wagwaan", "hot", "skull"] b = hot_redis.List(a) c = hot_redis.List(a, key=b.key) self.assertItemsEqual(a, c)
def test_len(self): a = ["wagwaan", "hot", "skull"] self.assertEqual(len(a), len(hot_redis.List(a)))
def test_iter(self): a = ["wagwaan", "hot", "skull"] for i, x in enumerate(hot_redis.List(a)): self.assertEquals(x, a[i])
def test_empty(self): self.assertEquals(hot_redis.List(), [])
def test_value(self): a = ["wagwaan", "hot", "skull"] self.assertEquals(hot_redis.List(a), a)
def test_count(self): a = ["wagwaan", "hot", "skull"] * 10 b = hot_redis.List(a) self.assertEquals(a.count("wagwaan"), b.count("wagwaan")) self.assertEquals(a.count("popcaan"), b.count("popcaan"))
from urllib.parse import urlparse import hot_redis import hug import requests __version__ = '0.0.3' AUTH = ('tim', 'anr94230890tnarsikantAWFUNRSkviawentha') REDIS_AUTH = urlparse(os.environ.get('REDISCLOUD_URL')) ENDPOINT = 'http://tims-todo-list.herokuapp.com/todos' hot_redis.configure({ 'host': REDIS_AUTH.hostname, 'port': REDIS_AUTH.port or 6379, 'password': REDIS_AUTH.password }) todos = hot_redis.List(key='my_todos') authentication = hug.authentication.basic(hug.authentication.verify(*AUTH)) @hug.get('/todos') def get_todos(): '''Returns a list of all my todo items''' return list(todos) @hug.post('/todos', requires=authentication) def add_todo(todo): '''Adds a new todo item''' todos.append(todo)
def test_contains(self): a = ["wagwaan", "hot", "skull"] b = hot_redis.List(a) self.assertIn("wagwaan", a) self.assertNotIn("hotskull", a)
def test_index(self): a = ["wagwaan", "hot", "skull"] * 10 b = hot_redis.List(a) c = "wagwaan" self.assertEquals(a.index(c), b.index(c)) self.assertRaises(ValueError, lambda: b.index("popcaan"))