Skip to content

Commit f8ea7b9

Browse files
committed
initial commit
0 parents  commit f8ea7b9

File tree

10 files changed

+251
-0
lines changed

10 files changed

+251
-0
lines changed

.circleci/config.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
# Python CircleCI 2.0 configuration file
3+
#
4+
# Check https://circleci.com/docs/2.0/language-python/ for more details
5+
#
6+
version: 2
7+
jobs:
8+
build:
9+
docker:
10+
- image: circleci/python:2.7.15
11+
- image: redisai/redisai:latest
12+
13+
working_directory: ~/repo
14+
15+
steps:
16+
- checkout
17+
18+
- restore_cache: # Download and cache dependencies
19+
keys:
20+
- v1-dependencies-{{ checksum "requirements.txt" }}
21+
# fallback to using the latest cache if no exact match is found
22+
- v1-dependencies-
23+
24+
- run:
25+
name: install dependencies
26+
command: |
27+
virtualenv venv
28+
. venv/bin/activate
29+
pip install -r requirements.txt
30+
31+
- save_cache:
32+
paths:
33+
- ./venv
34+
key: v1-dependencies-{{ checksum "requirements.txt" }}
35+
36+
- run:
37+
name: run tests
38+
command: |
39+
. venv/bin/activate
40+
REDIS_PORT=6379 python test/test.py
41+
42+
- store_artifacts:
43+
path: test-reports
44+
destination: test-reports
45+
46+
build_nightly:
47+
docker:
48+
- image: circleci/python:2.7.15
49+
- image: redislabs/redisearch:edge
50+
51+
working_directory: ~/repo
52+
53+
steps:
54+
- checkout
55+
56+
- restore_cache: # Download and cache dependencies
57+
keys:
58+
- v1-dependencies-{{ checksum "requirements.txt" }}
59+
# fallback to using the latest cache if no exact match is found
60+
- v1-dependencies-
61+
62+
- run:
63+
name: install dependencies
64+
command: |
65+
virtualenv venv
66+
. venv/bin/activate
67+
pip install -r requirements.txt
68+
69+
- save_cache:
70+
paths:
71+
- ./venv
72+
key: v1-dependencies-{{ checksum "requirements.txt" }}
73+
74+
- run:
75+
name: run tests
76+
command: |
77+
. venv/bin/activate
78+
REDIS_PORT=6379 python test/test.py
79+
80+
# no need for store_artifacts on nightly builds
81+
82+
workflows:
83+
version: 2
84+
commit:
85+
jobs:
86+
- build
87+
nightly:
88+
triggers:
89+
- schedule:
90+
cron: "0 0 * * *"
91+
filters:
92+
branches:
93+
only:
94+
- master
95+
jobs:
96+
- build_nightly

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.project
2+
.pydevproject
3+
*.pyc
4+
.venv/

LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
BSD 2-Clause License
2+
3+
Copyright (c) 2019, Redis Labs
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[![license](https://img.shields.io/github/license/RedisAI/redisai-py.svg)](https://github.com/RedisAI/redisai-py-go)
2+
[![PyPI version](https://badge.fury.io/py/redisai.svg)](https://badge.fury.io/py/redisai)
3+
[![CircleCI](https://circleci.com/gh/RedisAI/redisai-py/tree/master.svg?style=svg)](https://circleci.com/gh/RedisAI/redisai-py/tree/master)
4+
[![GitHub issues](https://img.shields.io/github/release/RedisAI/redisai-py.svg)](https://github.com/RedisAI/redisai-py/releases/latest)
5+
6+
7+
# RedisAI Python Client
8+
9+
10+
## Installing
11+
12+
1. Install Redis 5.0 or above
13+
14+
2. [Install RedisAI](http://redisai.io)
15+
16+
3. Install the python client
17+
18+
```sh
19+
$ pip install redisai
20+
```
21+
22+
23+

redisai/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .client import Client, Type
2+
3+

redisai/_util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import six
2+
3+
def to_string(s):
4+
if isinstance(s, six.string_types):
5+
return s
6+
elif isinstance(s, bytes):
7+
return s.decode('utf-8')
8+
else:
9+
return s # Not a string we care about

redisai/client.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from redis import StrictRedis
2+
from redis._compat import (long, nativestr)
3+
from enum import Enum
4+
import six
5+
6+
class Type(Enum):
7+
FLOAT=1
8+
DOUBLE=2
9+
INT8=3
10+
INT16=4
11+
INT32=5
12+
INT64=6
13+
UINT8=7
14+
UINT16=8
15+
16+
17+
class Client(StrictRedis):
18+
19+
def __init__(self, *args, **kwargs):
20+
"""
21+
Create a new Client optional host and port
22+
23+
If conn is not None, we employ an already existing redis connection
24+
"""
25+
StrictRedis.__init__(self, *args, **kwargs)
26+
27+
# Set the module commands' callbacks
28+
MODULE_CALLBACKS = {
29+
'AI.TENSORSET': lambda r: r and nativestr(r) == 'OK',
30+
}
31+
for k, v in six.iteritems(MODULE_CALLBACKS):
32+
self.set_response_callback(k, v)
33+
34+
35+
def tensorset(self, key, type, dimensions, tensor):
36+
args = ['AI.TENSORSET', key, type.name] + dimensions + ['VALUES'] + tensor
37+
38+
return self.execute_command(*args)
39+
40+

redisai/test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import six
2+
import json
3+
import unittest
4+
from unittest import TestCase
5+
from .client import Client, Type
6+
7+
rai = None
8+
port = 6379
9+
10+
class RedisAITestCase(TestCase):
11+
12+
def setUp(self):
13+
global rai
14+
rai = Client(port=port)
15+
rai.flushdb()
16+
17+
def testTensorSet(self):
18+
"Test basic TENSORSET"
19+
20+
self.assertTrue(rai.tensorset("key", Type.FLOAT, ["1"], ["2"]))
21+
22+
23+
24+
if __name__ == '__main__':
25+
unittest.main()

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
hiredis>=0.2.0
2+
redis>=2.10
3+
rmtest>=0.2
4+
six>=1.10.0

setup.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
#!/usr/bin/env python
3+
from setuptools import setup, find_packages
4+
5+
6+
setup(
7+
name='redisai',
8+
version='0.1.0',
9+
10+
description='RedisAI Python Client',
11+
url='http://github.com/RedisAI/redisai-py',
12+
packages=find_packages(),
13+
install_requires=['redis', 'hiredis', 'rmtest'],
14+
classifiers=[
15+
'Development Status :: 4 - Beta',
16+
'Intended Audience :: Developers',
17+
'License :: OSI Approved :: BSD License',
18+
'Programming Language :: Python :: 2.7',
19+
'Topic :: Database',
20+
'Topic :: Software Development :: Testing'
21+
]
22+
)

0 commit comments

Comments
 (0)