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 get(self): count = set() with hot_redis.transaction(): # for consistency for item in self.pnset: if PNCounter(get_pncounter_item_pnset_key(self.key, item)).get() <= 0: self.pnset.remove(item) # Garbage Collection else: count.add(item) return count
def add(self, pos_stamp, pos_stamp_next, x): with hot_redis.transaction(): x = chr(x) pos_stamp = float(pos_stamp) pos_stamp_next = float(pos_stamp_next) pos = pos_stamp + (pos_stamp_next - pos_stamp) / 2 self.pps[str(pos)] = x self.tags.append(str(pos)) self.tags.sort() # optimize self.persist[str(pos)] = YES
def insert(self, ch, pos): index = self.user_list.users.index(self.user) pos = int(pos) no_of_users = len(self.user_list.users) print 'no of users === ', no_of_users lower_bound = 0 lower_bound_persist = 0 upper_bound_persist = 0 found = False with hot_redis.transaction(): self.tags.sort() for tag in self.tags: if self.pps[tag] != PHI: lower_bound += 1 if lower_bound == pos: found = True break print self.tags ltag = self.tags[lower_bound] rtag = self.tags[lower_bound + 1] if self.persist[ltag] == YES and self.persist[rtag] == YES: print ltag, rtag, ' = YY' left = float(ltag) right = float(rtag) elif self.persist[ltag] == NO and self.persist[rtag] == NO: left = float(ltag) right = float(rtag) elif self.persist[ltag] == NO and self.persist[rtag] == YES: for p in range(lower_bound - 1, -1, -1): if self.persist[self.tags[p]] == YES: lower_bound_persist = str(p) break left = float(ltag) lower_bound_persist = float(self.tags[lower_bound_persist]) right = lower_bound_persist + (index + 1) * ( float(rtag) - lower_bound_persist) / no_of_users else: for p in range(lower_bound + 2, len(self.tags), 1): if self.persist[self.tags[p]] == YES: upper_bound_persist = str(p) break right = float(rtag) upper_bound_persist = float(self.tags[upper_bound_persist]) left = float(ltag) + index * (upper_bound_persist - float(ltag)) / no_of_users print left, right, ' = here insert' if found is True: self.add(left, right, ch) print self.piece(0, 1)
def add_client(self, client_id): # Generating a client list key for this key new_client = get_client_key(self.key, client_id) with hot_redis.transaction(): # Adding a new state to all the existing clients for client in self.client_list: hot_redis.Dict(key=client, client=connection)[new_client] = 0 # Adding client to GCounter instance's client list self.client_list.add(new_client) # Adding a new state dictionary for this GCounter client new_client_state = hot_redis.Dict(key=new_client, client=connection) for client in self.client_list: new_client_state[client] = 0
def add_client(self, client_id): # Generating a client list key for this key new_client = get_client_key(self.key, client_id) with hot_redis.transaction(): # Adding a new state to all the existing clients for client in self.client_list: hot_redis.Dict(key=client, client=connection)[new_client] = str({'timestamp': -1, 'value': None}) # Adding client to LWWERegister instance's client list self.client_list.add(new_client) # Adding a new state dictionary for this LWWERegister client new_client_state = hot_redis.Dict(key=new_client, client=connection) for client in self.client_list: new_client_state[client] = str({'timestamp': -1, 'value': None})
def attach(self, tag, x): with hot_redis.transaction(): self.pps[str(tag)] = x self.tags.append(str(tag)) self.tags.sort() # optimize self.persist[str(tag)] = YES
def transaction(): """ """ return hr.transaction()
def get_change_id(self): with hot_redis.transaction(): id = self.id.value self.id.value = id + 1 return self.id.value
def add(self, user): with hot_redis.transaction(): number_of_users = len(self.users.items()) self.users[user.lower()] = number_of_users self.user_changes[user.lower()] = ''