-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|
||
|
||
|