Skip to content

Instantly share code, notes, and snippets.

@Anakin-Hao
Created May 9, 2019 02:11
Show Gist options
  • Save Anakin-Hao/ebc53a0a6b1cc9c1ad627f713a19b7d7 to your computer and use it in GitHub Desktop.
Save Anakin-Hao/ebc53a0a6b1cc9c1ad627f713a19b7d7 to your computer and use it in GitHub Desktop.
ignite test
from pyignite import Client
from pyignite.datatypes.cache_config import CacheMode
from pyignite.datatypes.prop_codes import *
from pyignite.exceptions import SocketError
import time
nodes = [('100.108.0.16',10800)]
nodes = [('100.108.0.2', 10800), ('100.108.0.5',10800), ('100.108.0.6',10800)]
nodes = [('100.124.0.5',10800), ('100.110.0.7',10800)]
client = Client(timeout=4.0)
client.connect(nodes)
print('Connected to {}'.format(client))
my_cache = client.get_or_create_cache({
PROP_NAME: 'my_cache',
PROP_CACHE_MODE: CacheMode.REPLICATED,
})
my_cache.put('test_key', 0)
# abstract main loop
while True:
try:
# do the work
test_value = my_cache.get('test_key')
print(test_value)
my_cache.put('test_key', test_value + 1)
except (OSError, SocketError) as e:
# recover from error (repeat last command, check data
# consistency or just continue − depends on the task)
print('Error: {}'.format(e))
time.sleep(1)
print('Last value: {}'.format(my_cache.get('test_key')))
print('Reconnected to {}'.format(client))
except Exception as ex:
print('Error: {}'.format(ex))
time.sleep(1)
print('Last value: {}'.format(my_cache.get('test_key')))
print('Reconnected to {}'.format(client))
finally:
time.sleep(.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment