Skip to main content

A GraphQL interface for Redis Database.

Project description

GredisQL

A GraphQL interface for Redis Database.

How To Install

pip install gredisql

If you find this project interesting, you can always appreciate it by giving it a Star. :D

A Background of GredisQL

background_image

Motivation

  1. I was bored, been sick for a while, had to lie on the bed. So I needed to create something.
  2. Redis has Web interface ( actually a REST interface), so I urged to build one in GraphQL.
  3. There are some pretty amazing GraphQL libraries around python echo system, I wanted to try them.
  4. Last but not least, jump into quick coding session, engage and nurture the human mind. LOL

Design Philosophy

  1. All the data mutation and query are not separated here by action and most probably all the actions are performed via query operation.
  2. Technically all the requests sent to the GraphQL server was in POST, so I was initially okay with the implementation.
  3. Strawberry-Graphql is kind of server agnostic so either you can use ASGI or WSGI counterpart.
  4. Currently limiting the implementation with WSGI server, but I've plan to adopt ASGI in the journey, to support subscription.
  5. Not all Redis commands are found in the implementation, I'll try to cover it in the process.

Inspiration and Tools I used

  1. redis==5.0.0 is used to communicate with the Redis database.
  2. strawberry-graphql is used to do the heavy lifting. Also, I tried ariadne which is also another cool tool to try with.

Features and Future Plans

  1. String Commands

    • GET, SET, MSET, MGET
    • INCRBY, DECRBY, INCRBYFLOAT
    • APPEND, GETEX, GETDEL
    • EXPIRE, EXPIREAT
    • KEYS, EXISTS, DELETE
  2. List Commands

    • LPUSH, RPUSH
    • LPOP, RPOP
    • LRANGE
    • LLEN
  3. Set Commands

    • SADD, SCARD
    • SDIFF, SDIFFSTORE
    • SINTER, SINTERSTORE
    • SISMEMBER, SMEMBERS
    • SMOVE, SPOP
  4. Hash Commands

    • HSET, HGET
    • HGETALL
    • HDEL
    • HLEN
    • HKEYS, HVALS
  5. Sorted Set Commands

    • ZADD
    • ZRANGE, ZREVRANGE
    • ZCARD
    • ZSCORE
    • ZREM
    • ZCOUNT

And many more to come in the future iteration.

Example GraphQL Queries

String Operations

query {
  set(name: "mykey", value: "myvalue")
  get(name: "mykey")
  mset(
    mappings: [
      { key: "key1", value: "value1" }
      { key: "key2", value: "value2" }
    ]
  )
  mget(keys: ["key1", "key2"])
}

List Operations

query {
  lpush(name: "mylist", values: ["one", "two", "three"])
  lrange(name: "mylist", start: 0, end: -1)
  llen(name: "mylist")
}

Hash Operations

query {
  hset(name: "myhash", key: "field1", value: "value1")
  hget(name: "myhash", key: "field1")
  hgetall(name: "myhash")
}

Sorted Set Operations

query {
  zadd(name: "myset", mapping: {"member1": 1.0, "member2": 2.0})
  zrange(name: "myset", start: 0, end: -1, withscores: true)
  zcard(name: "myset")
}

Quick Starting the GraphQL Server

if __name__ == "__main__":
    from gredisql.core import Server

    server = Server()
    server.run()

You can specify the host, port and debug mode in while instantiating the GraphQL server. Simply write,

if __name__ == "__main__":

    REDIS_HOST = 'redis-4343.c8.us-east-1-4.ec2.cloud.redislabs.com'
    REDIS_PORT = 16292
    REDIS_PASSWORD = 'your-secret-password'

    from gredisql.core import Server

    server = Server(
         REDIS_HOST=REDIS_HOST,
         REDIS_PORT=REDIS_PORT,
         REDIS_PASSWORD=REDIS_PASSWORD
    )
    server.run()

Now navigate to http://localhost:5055/graphql and voilà.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gredisql-0.0.10.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gredisql-0.0.10-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file gredisql-0.0.10.tar.gz.

File metadata

  • Download URL: gredisql-0.0.10.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for gredisql-0.0.10.tar.gz
Algorithm Hash digest
SHA256 1799afea2d945aafd7e4caa10b6efb0d7cd8c569ef965e3e6e1a3b06f8ac1a1c
MD5 fa3e4c63a46453349789d9b123c81e01
BLAKE2b-256 c50e777f989ede6d095eb249a38b490255d1bca223caa414c0279a538992e2db

See more details on using hashes here.

File details

Details for the file gredisql-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: gredisql-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for gredisql-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 63a2abe2c03ec07aa2788a7880d651638a35b7626b8b0e5c7b39f655c9c6e6af
MD5 64eda9092dc284fb69e13daf5d4bc2e4
BLAKE2b-256 b5805600a93b1aa8d99160cc4a3b0d8e8d6ac154e13dff98660ece8dae266c0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page