import uuid
import redis
local_redis = redis.StrictRedis()
def add_id():
redis_key = "uuid:{}".format(local_redis.incr("global:uuid"))
local_redis.set(redis_key, uuid.uuid4())
local_redis.flushdb()
local_redis.dbsize()
0
while 1:
add_id()
--------------------------------------------------------------------------- ResponseError Traceback (most recent call last) <ipython-input-9-cf0e1403ae2e> in <module>() 1 while 1: ----> 2 add_id() <ipython-input-4-43889de8ec59> in add_id() 4 def add_id(): 5 redis_key = "uuid:{}".format(local_redis.incr("global:uuid")) ----> 6 local_redis.set(redis_key, uuid.uuid4()) 7 /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/redis/client.py in set(self, name, value, ex, px, nx, xx) 1070 if xx: 1071 pieces.append('XX') -> 1072 return self.execute_command('SET', *pieces) 1073 1074 def __setitem__(self, name, value): /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/redis/client.py in execute_command(self, *args, **options) 571 try: 572 connection.send_command(*args) --> 573 return self.parse_response(connection, command_name, **options) 574 except (ConnectionError, TimeoutError) as e: 575 connection.disconnect() /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/redis/client.py in parse_response(self, connection, command_name, **options) 583 def parse_response(self, connection, command_name, **options): 584 "Parses a response from the Redis server" --> 585 response = connection.read_response() 586 if command_name in self.response_callbacks: 587 return self.response_callbacks[command_name](response, **options) /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/redis/connection.py in read_response(self) 580 raise 581 if isinstance(response, ResponseError): --> 582 raise response 583 return response 584 ResponseError: OOM command not allowed when used memory > 'maxmemory'.
def add_id_expire():
count = local_redis.incr("global:uuid")
redis_key = "uuid:{}".format(count)
local_redis.set(redis_key, uuid.uuid4())
if count <= 75:
local_redis.expire(redis_key, 300)
while 1:
add_id_expire()
--------------------------------------------------------------------------- ResponseError Traceback (most recent call last) <ipython-input-12-ec991e68f760> in <module>() 1 while 1: ----> 2 add_id_expire() <ipython-input-11-81168c95fe2f> in add_id_expire() 1 def add_id_expire(): ----> 2 count = local_redis.incr("global:uuid") 3 redis_key = "uuid:{}".format(count) 4 local_redis.set(redis_key, uuid.uuid4()) 5 if count <= 75: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/redis/client.py in incr(self, name, amount) 913 the value will be initialized as ``amount`` 914 """ --> 915 return self.execute_command('INCRBY', name, amount) 916 917 def incrby(self, name, amount=1): /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/redis/client.py in execute_command(self, *args, **options) 571 try: 572 connection.send_command(*args) --> 573 return self.parse_response(connection, command_name, **options) 574 except (ConnectionError, TimeoutError) as e: 575 connection.disconnect() /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/redis/client.py in parse_response(self, connection, command_name, **options) 583 def parse_response(self, connection, command_name, **options): 584 "Parses a response from the Redis server" --> 585 response = connection.read_response() 586 if command_name in self.response_callbacks: 587 return self.response_callbacks[command_name](response, **options) /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/redis/connection.py in read_response(self) 580 raise 581 if isinstance(response, ResponseError): --> 582 raise response 583 return response 584 ResponseError: OOM command not allowed when used memory > 'maxmemory'.
count = 0
while 1:
add_id()
count += 1
--------------------------------------------------------------------------- ResponseError Traceback (most recent call last) <ipython-input-14-6afc2379c935> in <module>() 1 count = 0 2 while 1: ----> 3 add_id() 4 count += 1 <ipython-input-4-43889de8ec59> in add_id() 3 local_redis = redis.StrictRedis() 4 def add_id(): ----> 5 redis_key = "uuid:{}".format(local_redis.incr("global:uuid")) 6 local_redis.set(redis_key, uuid.uuid4()) 7 /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/redis/client.py in incr(self, name, amount) 913 the value will be initialized as ``amount`` 914 """ --> 915 return self.execute_command('INCRBY', name, amount) 916 917 def incrby(self, name, amount=1): /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/redis/client.py in execute_command(self, *args, **options) 571 try: 572 connection.send_command(*args) --> 573 return self.parse_response(connection, command_name, **options) 574 except (ConnectionError, TimeoutError) as e: 575 connection.disconnect() /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/redis/client.py in parse_response(self, connection, command_name, **options) 583 def parse_response(self, connection, command_name, **options): 584 "Parses a response from the Redis server" --> 585 response = connection.read_response() 586 if command_name in self.response_callbacks: 587 return self.response_callbacks[command_name](response, **options) /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/redis/connection.py in read_response(self) 580 raise 581 if isinstance(response, ResponseError): --> 582 raise response 583 return response 584 ResponseError: OOM command not allowed when used memory > 'maxmemory'.
count
66018
local_redis.hgetall("person2")
{b'name': b'George Washington'}
twem_redis = redis.StrictRedis(port=22122)
twem_redis.sadd("countries", "US", "Canada", "Mexico")
3
twem_redis.smembers("countries")
{b'Canada', b'Mexico', b'US'}
twem_redis.rename("countries", "north-ameria")
twem_redis.smembers("north-ameria")
set()