You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
Adds connect-as-acl-user example. (#1684)
* Adds connect-as-acl-user example. * Adds blank line at end. * Set to private. * Adds examples folder to npmignore.
This commit is contained in:
@@ -16,3 +16,4 @@ lib/
|
||||
index.ts
|
||||
*.spec.*
|
||||
dist/lib/test-utils.*
|
||||
examples/
|
||||
|
32
examples/connect-as-acl-user/connect-as-acl-user.js
Normal file
32
examples/connect-as-acl-user/connect-as-acl-user.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// Connect to Redis 6.x as an ACL user. Attempt to run a command
|
||||
// that the user is allowed to execute, and a command that the
|
||||
// user is not allowed to execute.
|
||||
|
||||
// Create the test user in redis-cli with this command:
|
||||
// acl setuser testuser on >testpassword +ping
|
||||
|
||||
import { createClient } from 'redis';
|
||||
|
||||
const connectWithACLUser = async () => {
|
||||
const client = createClient({
|
||||
url: 'redis://testuser:testpassword@127.0.0.1:6379'
|
||||
});
|
||||
|
||||
await client.connect();
|
||||
|
||||
// Returns PONG
|
||||
console.log(`Response from PING command: ${await client.ping()}`);
|
||||
|
||||
try {
|
||||
// This will error as this user is not allowed to run this command...
|
||||
console.log(`Response from GET command: ${await client.get('somekey')}`);
|
||||
} catch (e) {
|
||||
console.log(`GET command failed: ${e.message}`);
|
||||
}
|
||||
|
||||
await client.quit();
|
||||
}
|
||||
|
||||
|
||||
connectWithACLUser();
|
||||
|
110
examples/package-lock.json
generated
Normal file
110
examples/package-lock.json
generated
Normal file
@@ -0,0 +1,110 @@
|
||||
{
|
||||
"name": "node-redis-examples",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "node-redis-examples",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"redis": "next"
|
||||
}
|
||||
},
|
||||
"node_modules/cluster-key-slot": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.0.tgz",
|
||||
"integrity": "sha512-2Nii8p3RwAPiFwsnZvukotvow2rIHM+yQ6ZcBXGHdniadkYGZYiGmkHJIbZPIV9nfv7m/U1IPMVVcAhoWFeklw==",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/generic-pool": {
|
||||
"version": "3.8.2",
|
||||
"resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.8.2.tgz",
|
||||
"integrity": "sha512-nGToKy6p3PAbYQ7p1UlWl6vSPwfwU6TMSWK7TTu+WUY4ZjyZQGniGGt2oNVvyNSpyZYSB43zMXVLcBm08MTMkg==",
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
}
|
||||
},
|
||||
"node_modules/redis": {
|
||||
"version": "4.0.0-rc.3",
|
||||
"resolved": "https://registry.npmjs.org/redis/-/redis-4.0.0-rc.3.tgz",
|
||||
"integrity": "sha512-yvijGYWp3aOvqpFgqovUWLWSdHgjUEtScqJmjTfUXj/4kEHuSW2TERFQelIBnrGeKh8//eYlLpCFKCjDYT4NQw==",
|
||||
"dependencies": {
|
||||
"cluster-key-slot": "1.1.0",
|
||||
"generic-pool": "3.8.2",
|
||||
"redis-parser": "3.0.0",
|
||||
"yallist": "4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/redis-errors": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
|
||||
"integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60=",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/redis-parser": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz",
|
||||
"integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=",
|
||||
"dependencies": {
|
||||
"redis-errors": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/yallist": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"cluster-key-slot": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.0.tgz",
|
||||
"integrity": "sha512-2Nii8p3RwAPiFwsnZvukotvow2rIHM+yQ6ZcBXGHdniadkYGZYiGmkHJIbZPIV9nfv7m/U1IPMVVcAhoWFeklw=="
|
||||
},
|
||||
"generic-pool": {
|
||||
"version": "3.8.2",
|
||||
"resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.8.2.tgz",
|
||||
"integrity": "sha512-nGToKy6p3PAbYQ7p1UlWl6vSPwfwU6TMSWK7TTu+WUY4ZjyZQGniGGt2oNVvyNSpyZYSB43zMXVLcBm08MTMkg=="
|
||||
},
|
||||
"redis": {
|
||||
"version": "4.0.0-rc.3",
|
||||
"resolved": "https://registry.npmjs.org/redis/-/redis-4.0.0-rc.3.tgz",
|
||||
"integrity": "sha512-yvijGYWp3aOvqpFgqovUWLWSdHgjUEtScqJmjTfUXj/4kEHuSW2TERFQelIBnrGeKh8//eYlLpCFKCjDYT4NQw==",
|
||||
"requires": {
|
||||
"cluster-key-slot": "1.1.0",
|
||||
"generic-pool": "3.8.2",
|
||||
"redis-parser": "3.0.0",
|
||||
"yallist": "4.0.0"
|
||||
}
|
||||
},
|
||||
"redis-errors": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
|
||||
"integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60="
|
||||
},
|
||||
"redis-parser": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz",
|
||||
"integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=",
|
||||
"requires": {
|
||||
"redis-errors": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"yallist": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
|
||||
}
|
||||
}
|
||||
}
|
14
examples/package.json
Normal file
14
examples/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "node-redis-examples",
|
||||
"version": "1.0.0",
|
||||
"description": "node-redis 4 example script",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"redis": "next"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user