Advertisement
nsaunders

Untitled

Sep 28th, 2020
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1.  
  2.  
  3. root@mordor:~#
  4. root@mordor:~# docker container ls
  5. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  6. 0d51479c1b57 redislabs/redis-py "docker-entrypoint.s…" 12 minutes ago Up 12 minutes 6379/tcp redis-python
  7. ea782770bcff redis "docker-entrypoint.s…" 26 minutes ago Up 26 minutes 6379/tcp rd
  8. root@mordor:~#
  9. root@mordor:~# docker exec -it --user root redis-python bash
  10. root@0d51479c1b57:/usr/src/app#
  11. root@0d51479c1b57:/usr/src/app# ls
  12. requirements.txt test_db.py test_db.py.1
  13. root@0d51479c1b57:/usr/src/app#
  14. root@0d51479c1b57:/usr/src/app# cat test_db.py.1
  15. # The MIT License (MIT)
  16. #
  17. # Copyright (c) 2018 Redis Labs
  18. #
  19. # Permission is hereby granted, free of charge, to any person obtaining a copy
  20. # of this software and associated documentation files (the "Software"), to deal
  21. # in the Software without restriction, including without limitation the rights
  22. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  23. # copies of the Software, and to permit persons to whom the Software is
  24. # furnished to do so, subject to the following conditions:
  25. #
  26. # The above copyright notice and this permission notice shall be included in all
  27. # copies or substantial portions of the Software.
  28. #
  29. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  30. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  31. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  32. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  33. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  34. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  35. # SOFTWARE.
  36. #
  37. # Script Name: settings.sh
  38. # Author: Cihan Biyikoglu - github:(cihanb)
  39.  
  40.  
  41. import sys
  42. import redis
  43.  
  44. # try:
  45.  
  46. print (":: test_db.py")
  47.  
  48. if (len(sys.argv) <= 1):
  49. print("Need to provide a DB port to test connectiivity. Example: python Redis-Python-Sample.py 12000")
  50.  
  51. host_name = sys.argv[1]
  52. db_port = sys.argv[2]
  53.  
  54. print("Connecting to host={0} and port={1}".format(host_name,db_port))
  55. r = redis.StrictRedis(host=host_name, port=db_port, db=0)
  56.  
  57. print("Set key 'key1' to value '123' on host={0} and port={1}".format(host_name,db_port))
  58. r.set('key1', '123')
  59.  
  60. print("Get key 'key1' and validate value is '123' on host={0} and port={1}".format(host_name,db_port))
  61. if (r.get('key1') == b'123'):
  62. print("DB TEST PASSED")
  63. else:
  64. print("DB TEST FAILED: Can't find the key")
  65.  
  66. # except:
  67. # print("DB TEST FAILED")
  68.  
  69.  
  70. root@0d51479c1b57:/usr/src/app#
  71. root@0d51479c1b57:/usr/src/app# cat test_db.py
  72. import sys
  73. import redis
  74.  
  75. print (":: test_db.py")
  76.  
  77.  
  78.  
  79. r = redis.StrictRedis(host="127.0.0.1", port=6379, decode_responses=True)
  80.  
  81. r.set("msg:hello", "Hello Redis!!!")
  82.  
  83. msg = r.get("msg:hello")
  84.  
  85. print(msg)
  86.  
  87.  
  88. if (r.get('key1') == b'123'):
  89. print("DB TEST PASSED")
  90. else:
  91. print("DB TEST FAILED: Can't find the key")
  92. root@0d51479c1b57:/usr/src/app#
  93. root@0d51479c1b57:/usr/src/app# cat requirements.txt
  94. redis
  95.  
  96.  
  97.  
  98. root@0d51479c1b57:/usr/src/app#
  99. root@0d51479c1b57:/usr/src/app# python3 test_db.py
  100. Traceback (most recent call last):
  101. File "test_db.py", line 2, in <module>
  102. import redis
  103. ImportError: No module named 'redis'
  104. root@0d51479c1b57:/usr/src/app#
  105. root@0d51479c1b57:/usr/src/app# pip3 install redis
  106. Downloading/unpacking redis
  107. Downloading redis-3.5.3-py2.py3-none-any.whl (72kB): 72kB downloaded
  108. Installing collected packages: redis
  109. Successfully installed redis
  110. Cleaning up...
  111. root@0d51479c1b57:/usr/src/app#
  112. root@0d51479c1b57:/usr/src/app# python3 test_db.py
  113. :: test_db.py
  114. Hello Redis!!!
  115. DB TEST FAILED: Can't find the key
  116. root@0d51479c1b57:/usr/src/app#
  117.  
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement