Skip to main content

https://vercel.com/docs/storage/vercel-kv/rest-api

Project description

vercel-kv-sdk

vercel-kv-sdk is a simple toolkit for vercel kv db which warped from vercel REST API

Document

QuickStart

install

pip install vercel_kv_sdk

pull your vercel kv environment variables

vercel env pull .env.development.local

run this code to make the latest environment variables available to your project locally

rename your environment variables file

mv .env.development.local .env

then you can use vercel_kv_sdk in your project

from vercel_kv import KV

kv = KV()
kv.set("count",1)
count = kv.get("count")
print(f"now count is {count}")
# now count is 1

Using Options

In the SET command of Redis, there are several available options to configure the behavior of the command. Here are some common options in the SET command and their descriptions:

Options Description
ex Set the expiration time of the key in seconds. The key will be automatically deleted after the specified number of seconds.
px Set the expiration time of the key in milliseconds. The key will be automatically deleted after the specified number of milliseconds.
exat Set the value of the key only if it does not exist. If the key already exists, the SET command does not take effect.
pxat Set the value of the key only if it already exists. If the key does not exist, the SET command does not take effect.
keepTtl Preserve the existing expiration time of the key. Only used when overriding an existing key.

These options can be combined. For example, you can set the expiration time of the key to 10 seconds and set the value only if the key does not exist using the EX and NX options: SET key value EX 10 NX.

It is important to note that using options can have a certain impact on the performance of Redis, as additional operations will increase the overhead of command execution. Therefore, options should be used cautiously based on the actual requirements.

Example

kv = KV()
kv.set('temp','hello',ex=5)
print(f"now temp is {kv.get('temp')},and wait for 5 seconds...") # now temp is hello
time.sleep(5)
print(f"now temp is {kv.get('temp')}") # now temp is None

TODO

  • more user-friendly options input
  • complete functions: hset,hget

This project was forked from the python-vercel-kv project and improved,Lowering the python version threshold

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

vercel_kv_sdk-0.1.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

vercel_kv_sdk-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file vercel_kv_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: vercel_kv_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.1

File hashes

Hashes for vercel_kv_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 141881b7ddc1bfc2c83e959d62cd0998280007d6bff163c58ba66a417d34e70a
MD5 2a2f072dd5e788f6819a735e156c25b8
BLAKE2b-256 718eb431522af6c5a81a844644591e698129d4357e993d280e22e1fcc84ea90d

See more details on using hashes here.

File details

Details for the file vercel_kv_sdk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vercel_kv_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b726d5e49e7a4b2de648c2c46a056d2984654fd8524e871160f0ce0a64ae4a1d
MD5 95807086d277051393354a41f4fecada
BLAKE2b-256 f2ec7260519ade95d57a433d8d258c8bb9a83791b322ad69878c6f0a1292c4da

See more details on using hashes here.

Supported by

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