Using Redis in iPython

In [1]: import redis

In [2]: r = redis.Redis(host=’localhost’, port=6379, db=0)

In [3]: re = [
…: {
…: “cpu_util”: “18”,
…: “mem_size”: 4194303.9990234375,
…: “mem_util”: 0.0,
…: …


This content originally appeared on DEV Community and was authored by Santhosh Balasa

In [1]: import redis

In [2]: r = redis.Redis(host='localhost', port=6379, db=0)

In [3]: re = [
   ...:         {
   ...:             "cpu_util": "18",
   ...:             "mem_size": 4194303.9990234375,
   ...:             "mem_util": 0.0,
   ...:             "model": None,
   ...:             "re_temp": None,
   ...:             "reboot_reason": None,
   ...:             "role": "master",
   ...:             "serial":None,
   ...:             "slot": "0",
   ...:             "state": "OK",
   ...:             "status": 0,
   ...:             "id": "306f2fd7-229f-4aa8-b2c0-e420c85dcc3a",
   ...:             "cpu_temp": "",
   ...:             "cpu_temp_dgr": "",
   ...:             "load": 0,
   ...:             "re_temp_dgr": "",
   ...:             "role_priority": "",
   ...:             "up_datetime": "",
   ...:             "up_datetime_sec": "",
   ...:             "uptime": ""
   ...:         }
   ...:     ]

In [4]: re
Out[4]:
[{'cpu_util': '18',
  'mem_size': 4194303.9990234375,
  'mem_util': 0.0,
  'model': None,
  're_temp': None,
  'reboot_reason': None,
  'role': 'master',
  'serial': None,
  'slot': '0',
  'state': 'OK',
  'status': 0,
  'id': '306f2fd7-229f-4aa8-b2c0-e420c85dcc3a',
  'cpu_temp': '',
  'cpu_temp_dgr': '',
  'load': 0,
  're_temp_dgr': '',
  'role_priority': '',
  'up_datetime': '',
  'up_datetime_sec': '',
  'uptime': ''}]

In [5]: hostname = 'at-vie05d-rt1'

In [6]: hostname
Out[6]: 'at-vie05d-rt1'

In [7]: r.hset(f'router:{hostname}', 're', str(re))
Out[7]: 1

In [8]: v = r.hget(f'router:{hostname}', 're')

In [9]: import yaml

In [10]: re_from_redis = yaml.load(v)

In [11]: re_from_redis
Out[11]:
[{'cpu_util': '18',
  'mem_size': 4194303.9990234375,
  'mem_util': 0.0,
  'model': 'None',
  're_temp': 'None',
  'reboot_reason': 'None',
  'role': 'master',
  'serial': 'None',
  'slot': '0',
  'state': 'OK',
  'status': 0,
  'id': '306f2fd7-229f-4aa8-b2c0-e420c85dcc3a',
  'cpu_temp': '',
  'cpu_temp_dgr': '',
  'load': 0,
  're_temp_dgr': '',
  'role_priority': '',
  'up_datetime': '',
  'up_datetime_sec': '',
  'uptime': ''}]
In [43]: redis_client.hmset(f'router:{hostname}', {'data': str(data)})

-> Redis on windows:

winpty docker exec -it 8e76eea66688 redis-cli GET cnt:iface:72e76f51-1d54-4742-9462-1e29d0e88edb


This content originally appeared on DEV Community and was authored by Santhosh Balasa


Print Share Comment Cite Upload Translate Updates
APA

Santhosh Balasa | Sciencx (2021-05-31T03:52:19+00:00) Using Redis in iPython. Retrieved from https://www.scien.cx/2021/05/31/using-redis-in-ipython/

MLA
" » Using Redis in iPython." Santhosh Balasa | Sciencx - Monday May 31, 2021, https://www.scien.cx/2021/05/31/using-redis-in-ipython/
HARVARD
Santhosh Balasa | Sciencx Monday May 31, 2021 » Using Redis in iPython., viewed ,<https://www.scien.cx/2021/05/31/using-redis-in-ipython/>
VANCOUVER
Santhosh Balasa | Sciencx - » Using Redis in iPython. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/31/using-redis-in-ipython/
CHICAGO
" » Using Redis in iPython." Santhosh Balasa | Sciencx - Accessed . https://www.scien.cx/2021/05/31/using-redis-in-ipython/
IEEE
" » Using Redis in iPython." Santhosh Balasa | Sciencx [Online]. Available: https://www.scien.cx/2021/05/31/using-redis-in-ipython/. [Accessed: ]
rf:citation
» Using Redis in iPython | Santhosh Balasa | Sciencx | https://www.scien.cx/2021/05/31/using-redis-in-ipython/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.