Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
raresteak committed Mar 9, 2018
1 parent eedd0ae commit 9add633
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
29 changes: 29 additions & 0 deletions memcache_query.pylibmc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Connect to a memcached server over UDP, retrieve some keys
import pylibmc
# Setup connection
#TCP
#MEMCONN = pylibmc.Client(["192.168.168.168"], binary=True )
#UDP con
MEMCONN = pylibmc.Client(["udp:192.168.168.168"])
# Populate data
MEMCONN["myteststringkey"] = "The quick brown fox jumps over the lazy dog"

# Retreive the data 100 times
#for num in range(1000):
RET_DATA = MEMCONN["myteststringkey"]
print(RET_DATA)

'''
pylibmc has not implemented udp connections
$ ./memcache_query.pylibmc.sh
Traceback (most recent call last):
File "./memcache_query.pylibmc.sh", line 14, in <module>
RET_DATA = MEMCONN["myteststringkey"]
File "/usr/local/lib/python3.5/dist-packages/pylibmc/client.py", line 158, in __getitem__
value = self.get(key, _MISS_SENTINEL)
pylibmc.NotSupportedError: error 28 from memcached_get(myteststringkey): (0x20f87a0) ACTION NOT SUPPORTED -> libmemcached/get.cc:216
'''
20 changes: 20 additions & 0 deletions memcache_query.tcp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Connect to a memcached server over UDP, retrieve some keys
import socket
TCP_IP = "192.168.168.168"
TCP_PORT = 11211
MESSAGE = "get myteststringkey\r\n"
BUFFER_SIZE = 1024

# setup connection Ref https://wiki.python.org/moin/TcpCommunication
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_STREAM) # TCP
sock.connect((TCP_IP, TCP_PORT))
sock.send(MESSAGE.encode('utf-8') )
# If you don't add .encode() you get error TypeError: a bytes-like object is required, not 'str'
RESPONSE = sock.recv(BUFFER_SIZE)
#sock.shutdown()
sock.close()
print("Received..." + str(RESPONSE) )
16 changes: 16 additions & 0 deletions memcache_query.udp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Connect to a memcached server over UDP, retrieve some keys
import socket
UDP_IP = "192.168.168.168"
UDP_PORT = 11211
MESSAGE = "get myteststringkey\r\n"

# setup connection Ref https://wiki.python.org/moin/UdpCommunication
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE.encode('utf-8'), (UDP_IP, UDP_PORT))



0 comments on commit 9add633

Please sign in to comment.