-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
valkey - storage adapter for valkey (redis OSS) (#1153)
* valkey - storage adapter for valkey (redis OSS) * updating the class and type naming * adding in its valkey instance * removing tls as not needed * adding in directory * Update README.md
- Loading branch information
Showing
10 changed files
with
602 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
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
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,22 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017-2021 Luke Childs | ||
Copyright (c) 2021-2022 Jared Wray | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,101 @@ | ||
# @keyv/valkey [<img width="100" align="right" src="https://jaredwray.com/images/keyv-symbol.svg" alt="keyv">](https://github.com/jaredwra/keyv) | ||
|
||
> Valkey storage adapter for Keyv | ||
[](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml) | ||
[](https://codecov.io/gh/jaredwray/keyv) | ||
[](https://www.npmjs.com/package/@keyv/valkey) | ||
[](https://npmjs.com/package/@keyv/valkey) | ||
|
||
[Valkey](https://valkey.io) storage adapter for [Keyv](https://github.com/jaredwray/keyv). | ||
|
||
Valkey is the open source replacement to Redis which decided do a [dual license](https://redis.com/blog/redis-adopts-dual-source-available-licensing/) approach moving forward. Valkey is a drop-in replacement for Redis and is fully compatible with the Redis protocol. | ||
|
||
We are using the [iovalkey](https://www.npmjs.com/package/iovalkey) which is a Node.js client for Valkey based on the `ioredis` client. | ||
|
||
## Install | ||
|
||
```shell | ||
npm install --save keyv @keyv/valkey | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import Keyv from 'keyv'; | ||
import KeyvValkey from '@keyv/valkey'; | ||
|
||
const keyv = new Keyv(new KeyvValkey('redis://user:pass@localhost:6379')); | ||
keyv.on('error', handleConnectionError); | ||
``` | ||
|
||
e.g: | ||
|
||
```js | ||
const keyv = new Keyv(new KeyvValkey('redis://user:pass@localhost:6379', { disable_resubscribing: true })); | ||
``` | ||
|
||
Or you can manually create a storage adapter instance and pass it to Keyv: | ||
|
||
```js | ||
import Keyv from 'keyv'; | ||
import KeyvValkey from '@keyv/redis'; | ||
|
||
const KeyvValkey = new KeyvValkey('redis://user:pass@localhost:6379'); | ||
const keyv = new Keyv({ store: KeyvValkey }); | ||
``` | ||
|
||
Or reuse a previous Redis instance: | ||
|
||
```js | ||
import Keyv from 'keyv'; | ||
import Redis from 'ioredis'; | ||
import KeyvValkey from '@keyv/redis'; | ||
|
||
const redis = new Redis('redis://user:pass@localhost:6379'); | ||
const KeyvValkey = new KeyvValkey(redis); | ||
const keyv = new Keyv({ store: KeyvValkey }); | ||
``` | ||
|
||
Or reuse a previous Redis cluster: | ||
|
||
```js | ||
import Keyv from 'keyv'; | ||
import Redis from 'ioredis'; | ||
import KeyvValkey from '@keyv/redis'; | ||
|
||
const redis = new Redis.Cluster('redis://user:pass@localhost:6379'); | ||
const KeyvValkey = new KeyvValkey(redis); | ||
const keyv = new Keyv({ store: KeyvValkey }); | ||
``` | ||
## Options | ||
|
||
### useRedisSets | ||
|
||
The `useRedisSets` option lets you decide whether to use Redis sets for key management. By default, this option is set to `true`. | ||
|
||
When `useRedisSets` is enabled (`true`): | ||
|
||
- A namespace for the Redis sets is created, and all created keys are added to this. This allows for group management of keys. | ||
- When a key is deleted, it's removed not only from the main storage but also from the Redis set. | ||
- When clearing all keys (using the `clear` function), all keys in the Redis set are looked up for deletion. The set itself is also deleted. | ||
|
||
**Note**: In high-performance scenarios, enabling `useRedisSets` might lead to memory leaks. If you're running a high-performance application or service, it is recommended to set `useRedisSets` to `false`. | ||
|
||
If you decide to set `useRedisSets` as `false`, keys will be handled individually and Redis sets won't be utilized. | ||
|
||
However, please note that setting `useRedisSets` to `false` could lead to performance issues in production when using the `clear` function, as it will need to iterate over all keys to delete them. | ||
|
||
#### Example | ||
|
||
Here's how you can use the `useRedisSets` option: | ||
|
||
```js | ||
import Keyv from 'keyv'; | ||
|
||
const keyv = new Keyv(new KeyvValkey('redis://user:pass@localhost:6379', { useRedisSets: false })); | ||
``` | ||
|
||
## License | ||
|
||
[MIT © Jared Wray](LISCENCE) |
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,85 @@ | ||
{ | ||
"name": "@keyv/valkey", | ||
"version": "1.0.0", | ||
"description": "Valkey storage adapter for Keyv", | ||
"type": "module", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.js" | ||
} | ||
}, | ||
"scripts": { | ||
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean", | ||
"prepare": "yarn build", | ||
"test": "xo --fix && vitest run --coverage", | ||
"test:ci": "xo && vitest --run --sequence.setupFiles=list", | ||
"clean": "rimraf ./node_modules ./coverage ./dist" | ||
}, | ||
"xo": { | ||
"rules": { | ||
"import/no-named-as-default": "off", | ||
"unicorn/prefer-module": "off", | ||
"unicorn/prefer-event-target": "off", | ||
"unicorn/prefer-node-protocol": "off", | ||
"unicorn/no-typeof-undefined": "off", | ||
"import/extensions": "off", | ||
"@typescript-eslint/no-unsafe-call": "off", | ||
"@typescript-eslint/no-unsafe-assignment": "off", | ||
"@typescript-eslint/no-unsafe-return": "off", | ||
"unicorn/prefer-ternary": "off", | ||
"unicorn/no-array-callback-reference": "off", | ||
"import/no-extraneous-dependencies": "off", | ||
"@typescript-eslint/no-confusing-void-expression": "off" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/jaredwray/keyv.git", | ||
"directory": "packages/valkey" | ||
}, | ||
"keywords": [ | ||
"redis", | ||
"valkey", | ||
"valkeyio", | ||
"ioredis", | ||
"keyv", | ||
"storage", | ||
"adapter", | ||
"key", | ||
"value", | ||
"store", | ||
"cache", | ||
"ttl" | ||
], | ||
"author": "Jared Wray <[email protected]> (http://jaredwray.com)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/jaredwray/keyv/issues" | ||
}, | ||
"homepage": "https://github.com/jaredwray/keyv", | ||
"dependencies": { | ||
"iovalkey": "^0.1.0" | ||
}, | ||
"devDependencies": { | ||
"@keyv/test-suite": "*", | ||
"keyv": "^5.0.3", | ||
"rimraf": "^6.0.1", | ||
"timekeeper": "^2.3.1", | ||
"tsd": "^0.31.2", | ||
"xo": "^0.59.3" | ||
}, | ||
"tsd": { | ||
"directory": "test" | ||
}, | ||
"engines": { | ||
"node": ">= 18" | ||
}, | ||
"files": [ | ||
"dist", | ||
"LICENSE" | ||
] | ||
} |
Oops, something went wrong.