def test_hdel(self, tracker, redis, keys): redis.hmset('foo', {'one': '1', 'two': '2', 'three': '3'}) redis.hdel('foo', *keys) sleep(TIME_SLEEP) assert_items_equal( tracker.call_args_list, [ call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyevent@*__:*', 'data': 1, }), call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyspace@*__:*', 'data': 2, }), call({ 'type': 'pmessage', 'pattern': '__keyspace@*__:*', 'channel': '__keyspace@0__:foo', 'data': 'hset', }), call({ 'type': 'pmessage', 'pattern': '__keyevent@*__:*', 'channel': '__keyevent@0__:hset', 'data': 'foo', }), call({ 'type': 'pmessage', 'pattern': '__keyspace@*__:*', 'channel': '__keyspace@0__:foo', 'data': 'hdel', }), call({ 'type': 'pmessage', 'pattern': '__keyevent@*__:*', 'channel': '__keyevent@0__:hdel', 'data': 'foo', }), ], )
def test_del(self, tracker, redis): redis.set('foo', 'bar') redis.delete('foo') sleep(TIME_SLEEP) assert_items_equal( tracker.call_args_list, [ call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyevent@*__:*', 'data': 1, }), call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyspace@*__:*', 'data': 2, }), call({ 'type': 'pmessage', 'pattern': '__keyspace@*__:*', 'channel': '__keyspace@0__:foo', 'data': 'set', }), call({ 'type': 'pmessage', 'pattern': '__keyevent@*__:*', 'channel': '__keyevent@0__:set', 'data': 'foo', }), call({ 'type': 'pmessage', 'pattern': '__keyspace@*__:*', 'channel': '__keyspace@0__:foo', 'data': 'del', }), call({ 'type': 'pmessage', 'pattern': '__keyevent@*__:*', 'channel': '__keyevent@0__:del', 'data': 'foo', }), ], )
def test_subscribe_events(self, tracker): assert_items_equal( tracker.call_args_list, [ call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyevent@*__:*', 'data': 1, }), call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyspace@*__:*', 'data': 2, }), ], )
def test_listen_multiple_keys(self, create_service, tracker, redis, keys): create_service(uri_config_key=URI_CONFIG_KEY, keys=keys, dbs='*') redis.set('foo', '1') sleep(TIME_SLEEP) call_args_list = [ call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyspace@*__:foo', 'data': 1, }), call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyspace@*__:bar', 'data': 2, }), call({ 'type': 'pmessage', 'pattern': '__keyspace@*__:foo', 'channel': '__keyspace@0__:foo', 'data': 'set', }), ] assert_items_equal(tracker.call_args_list, call_args_list) redis.set('bar', '2') sleep(TIME_SLEEP) call_args_list.extend([ call({ 'type': 'pmessage', 'pattern': '__keyspace@*__:bar', 'channel': '__keyspace@0__:bar', 'data': 'set', }) ]) assert_items_equal(tracker.call_args_list, call_args_list)
def test_listen_multiple_events(self, create_service, tracker, redis, events): create_service(uri_config_key=URI_CONFIG_KEY, events=events, dbs='*') redis.set('foo', 'bar') sleep(TIME_SLEEP) call_args_list = [ call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyevent@*__:set', 'data': 1, }), call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyevent@*__:hset', 'data': 2, }), call({ 'type': 'pmessage', 'pattern': '__keyevent@*__:set', 'channel': '__keyevent@0__:set', 'data': 'foo', }), ] assert_items_equal(tracker.call_args_list, call_args_list) redis.hset('one', 'two', 'three') sleep(TIME_SLEEP) call_args_list.append( call({ 'type': 'pmessage', 'pattern': '__keyevent@*__:hset', 'channel': '__keyevent@0__:hset', 'data': 'one', })) assert_items_equal(tracker.call_args_list, call_args_list)
def test_listen_db(self, create_service, tracker, redis_db_1): create_service(uri_config_key=URI_CONFIG_KEY, keys='*', events='*', dbs=1) redis_db_1.set('foo', 'bar') sleep(TIME_SLEEP) assert_items_equal( tracker.call_args_list, [ call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyevent@1__:*', 'data': 1, }), call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyspace@1__:*', 'data': 2, }), call({ 'type': 'pmessage', 'pattern': '__keyspace@1__:*', 'channel': '__keyspace@1__:foo', 'data': 'set', }), call({ 'type': 'pmessage', 'pattern': '__keyevent@1__:*', 'channel': '__keyevent@1__:set', 'data': 'foo', }), ], )
def test_simple_events(self, tracker, redis, action, args, event_type): method = getattr(redis, action) method(*args) sleep(TIME_SLEEP) key = args[0] assert_items_equal( tracker.call_args_list, [ call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyevent@*__:*', 'data': 1, }), call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyspace@*__:*', 'data': 2, }), call({ 'type': 'pmessage', 'pattern': '__keyspace@*__:*', 'channel': '__keyspace@0__:{}'.format(key), 'data': event_type, }), call({ 'type': 'pmessage', 'pattern': '__keyevent@*__:*', 'channel': '__keyevent@0__:{}'.format(event_type), 'data': key, }), ], )
def test_expire(self, tracker, redis, action, ttl, wait_time): redis.set('foo', 'bar') method = getattr(redis, action) method('foo', ttl) sleep(TIME_SLEEP) call_args_list = [ call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyevent@*__:*', 'data': 1, }), call({ 'type': 'psubscribe', 'pattern': None, 'channel': '__keyspace@*__:*', 'data': 2, }), call({ 'type': 'pmessage', 'pattern': '__keyspace@*__:*', 'channel': '__keyspace@0__:foo', 'data': 'set', }), call({ 'type': 'pmessage', 'pattern': '__keyevent@*__:*', 'channel': '__keyevent@0__:set', 'data': 'foo', }), call({ 'type': 'pmessage', 'pattern': '__keyspace@*__:*', 'channel': '__keyspace@0__:foo', 'data': 'expire', }), call({ 'type': 'pmessage', 'pattern': '__keyevent@*__:*', 'channel': '__keyevent@0__:expire', 'data': 'foo', }), ] assert_items_equal(tracker.call_args_list, call_args_list) sleep(wait_time) call_args_list.extend([ call({ 'type': 'pmessage', 'pattern': '__keyspace@*__:*', 'channel': '__keyspace@0__:foo', 'data': 'expired', }), call({ 'type': 'pmessage', 'pattern': '__keyevent@*__:*', 'channel': '__keyevent@0__:expired', 'data': 'foo', }), ]) assert_items_equal(tracker.call_args_list, call_args_list)