Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

init first version

  • Loading branch information...
commit 4cf0f10d17b121c46327eaf48acfdabea82b27db 0 parents
Louis-Philippe Perron authored
19  README.md
Source Rendered
... ...
@@ -0,0 +1,19 @@
  1
+# node-redis-namespace
  2
+Similar in use to [redis-namespace](https://github.com/defunkt/redis-namespace) for node.
  3
+
  4
+# Install
  5
+	npm install redis-keyspace
  6
+
  7
+# Use
  8
+Use this library just as you would [node_redis](https://github.com/mranney/node_redis)
  9
+    
  10
+    redis = require("redis")
  11
+    redis_client = redis.createClient()
  12
+    redis_keyspace = require('redis-keyspace')
  13
+    client = redis_keyspace.createClient('bwf_data', redis_client)
  14
+    
  15
+    client.set('KOO', 'DOO', (err, reply) -> console.log( 'set reply: ' + reply + " err: " + err ))
  16
+    client.get('KOO', (err, reply) -> console.log( 'get reply: ' + reply + " err: " + err ))
  17
+
  18
+# Thanks
  19
+This is a CoffeeScript spinoff of ['node-redis-namespace'](https://github.com/arschles/node-redis-namespace) from ['Aaron Schlesinger'](https://github.com/arschles).
1  index.coffee
... ...
@@ -0,0 +1 @@
  1
+module.exports = require("./lib/redis-keyspace")
159  lib/redis-keyspace.coffee
... ...
@@ -0,0 +1,159 @@
  1
+exports.createClient = (prefix, redis) -> new RedisKeyspace(prefix, redis)
  2
+
  3
+NO_KEY = -1
  4
+FIRST_KEY = 0
  5
+LAST_KEY = 1
  6
+NOT_FIRST_KEY = 2
  7
+NOT_LAST_KEY = 3
  8
+ALL_KEYS = 4
  9
+ODDS_KEY = 5
  10
+UNKNOWN_KEY = 6
  11
+COMMANDS = 
  12
+  append: FIRST_KEY
  13
+  auth: NO_KEY
  14
+  bgrewriteaof: NO_KEY
  15
+  bgsave: NO_KEY
  16
+  blpop: NOT_LAST_KEY
  17
+  brpop: NOT_LAST_KEY
  18
+  brpoplpush: NOT_LAST_KEY
  19
+  "config get": NO_KEY
  20
+  "config set": NO_KEY
  21
+  "config resetstat": NO_KEY
  22
+  dbsize: NO_KEY
  23
+  "debug object": FIRST_KEY
  24
+  "debug segfault": NO_KEY
  25
+  decr: FIRST_KEY
  26
+  decrby: FIRST_KEY
  27
+  del: ALL_KEYS
  28
+  discard: NO_KEY
  29
+  echo: NO_KEY
  30
+  exec: NO_KEY
  31
+  exists: FIRST_KEY
  32
+  expire: FIRST_KEY
  33
+  expireat: FIRST_KEY
  34
+  flushall: NO_KEY
  35
+  flushdb: NO_KEY
  36
+  get: FIRST_KEY
  37
+  getbit: FIRST_KEY
  38
+  getrange: FIRST_KEY
  39
+  getset: FIRST_KEY
  40
+  hdel: FIRST_KEY
  41
+  hexists: FIRST_KEY
  42
+  hget: FIRST_KEY
  43
+  hgetall: FIRST_KEY
  44
+  hincrby: FIRST_KEY
  45
+  hkeys: FIRST_KEY
  46
+  hlen: FIRST_KEY
  47
+  hmget: FIRST_KEY
  48
+  hmset: FIRST_KEY
  49
+  hset: FIRST_KEY
  50
+  hsetnx: FIRST_KEY
  51
+  hvals: FIRST_KEY
  52
+  incr: FIRST_KEY
  53
+  incrby: FIRST_KEY
  54
+  info: NO_KEY
  55
+  keys: FIRST_KEY
  56
+  lastsave: NO_KEY
  57
+  lindex: FIRST_KEY
  58
+  linsert: FIRST_KEY
  59
+  llen: FIRST_KEY
  60
+  lpop: FIRST_KEY
  61
+  lpush: FIRST_KEY
  62
+  lpushx: FIRST_KEY
  63
+  lrange: FIRST_KEY
  64
+  lrem: FIRST_KEY
  65
+  lset: FIRST_KEY
  66
+  ltrim: FIRST_KEY
  67
+  mget: ALL_KEYS
  68
+  monitor: NO_KEY
  69
+  move: FIRST_KEY
  70
+  mset: ODDS_KEY
  71
+  msetnx: ODDS_KEY
  72
+  multi: NO_KEY
  73
+  object: NO_KEY
  74
+  persist: FIRST_KEY
  75
+  ping: NO_KEY
  76
+  psubscribe: NO_KEY
  77
+  publish: NO_KEY
  78
+  punsubscribe: NO_KEY
  79
+  quit: NO_KEY
  80
+  randomkey: NO_KEY
  81
+  rename: ALL_KEYS
  82
+  renamenx: ALL_KEYS
  83
+  rpop: FIRST_KEY
  84
+  rpoplpush: ALL_KEYS
  85
+  rpush: FIRST_KEY
  86
+  rpushx: FIRST_KEY
  87
+  sadd: FIRST_KEY
  88
+  save: NO_KEY
  89
+  scard: FIRST_KEY
  90
+  sdiff: ALL_KEYS
  91
+  sdiffstore: ALL_KEYS
  92
+  select: NO_KEY
  93
+  set: FIRST_KEY
  94
+  setbit: FIRST_KEY
  95
+  setex: FIRST_KEY
  96
+  setnx: FIRST_KEY
  97
+  setrange: FIRST_KEY
  98
+  shutdown: NO_KEY
  99
+  sinter: ALL_KEYS
  100
+  sinterstore: ALL_KEYS
  101
+  sismember: FIRST_KEY
  102
+  slaveof: NO_KEY
  103
+  smembers: FIRST_KEY
  104
+  smove: NOT_LAST_KEY
  105
+  sort: FIRST_KEY
  106
+  spop: FIRST_KEY
  107
+  srandmember: FIRST_KEY
  108
+  srem: FIRST_KEY
  109
+  strlen: FIRST_KEY
  110
+  subscribe: NO_KEY
  111
+  sunion: ALL_KEYS
  112
+  sunionstore: ALL_KEYS
  113
+  sync: NO_KEY
  114
+  ttl: FIRST_KEY
  115
+  type: FIRST_KEY
  116
+  unsubscribe: NO_KEY
  117
+  unwatch: NO_KEY
  118
+  watch: ALL_KEYS
  119
+  zadd: FIRST_KEY
  120
+  zcard: FIRST_KEY
  121
+  zcount: FIRST_KEY
  122
+  zincrby: FIRST_KEY
  123
+  zinterstore: UNKNOWN_KEY
  124
+  zrange: FIRST_KEY
  125
+  zrangebyscore: FIRST_KEY
  126
+  zrank: FIRST_KEY
  127
+  zrem: FIRST_KEY
  128
+  zremrangebyrank: FIRST_KEY
  129
+  zremrangebyscore: FIRST_KEY
  130
+  zrevrange: FIRST_KEY
  131
+  zrevrangebyscore: FIRST_KEY
  132
+  zrevrank: FIRST_KEY
  133
+  zscore: FIRST_KEY
  134
+  zunionstore: UNKNOWN_KEY
  135
+
  136
+class RedisKeyspace
  137
+  constructor: (@prefix, @redis) ->
  138
+    generate_key = (key) -> prefix + ":" + key
  139
+    create_method = (name, key_pos) ->
  140
+      (args...) ->
  141
+        func = args.pop()
  142
+        if key_pos is FIRST_KEY
  143
+          args[0] = generate_key(args[0])
  144
+        else if key_pos is LAST_KEY
  145
+          args[args.length - 1] == generate_key(args[args.length - 1])
  146
+        else if key_pos is ALL_KEYS or key_pos is NOT_FIRST_KEY or key_pos is NOT_LAST_KEY
  147
+          loop_start = 0
  148
+          loop_end = args.length
  149
+          if key_pos is NOT_FIRST_KEY
  150
+            loop_start++
  151
+          else if key_pos is NOT_LAST_KEY
  152
+            loop_end--
  153
+          i = loop_start
  154
+          while i < loop_end
  155
+            args[i] = generate_key(args[i])
  156
+            i++
  157
+        @redis.send_command name, args, func
  158
+    for k, v of COMMANDS
  159
+      RedisKeyspace::[k] = create_method( k, v)
27  package.json
... ...
@@ -0,0 +1,27 @@
  1
+{
  2
+	"name" : "redis-keyspace",
  3
+	"description" : "redis namespacing for node",
  4
+	"keywords" : ["redis", "key-value stores", "namespacing"],
  5
+	"version" : "0.2.0",
  6
+	"contributors": [
  7
+		{
  8
+			"name": "Louis-Philippe Perron",
  9
+			"web": "http://github.com/lp"
  10
+		}
  11
+	],
  12
+	"author" : "Louis-Philippe Perron <lp@spiralix.org> (http://github.com/lp/redis-keyspace)",
  13
+	"bugs" : {
  14
+		"web" : "http://github.com/lp/redis-keyspace/issues"
  15
+	},
  16
+	"main" : "./index.coffee",
  17
+	"directories" : {
  18
+		"lib" : "./lib"
  19
+	},
  20
+	"repository" : {
  21
+		"type" : "git",
  22
+		"url" : "git://github.com/lp/redis-keyspace.git"
  23
+	},
  24
+	"engines" : { "node" : ">=0.4.0"},
  25
+	"dependencies" : {"node-redis": "0.1.3", "coffee-script": "1.0.0"},
  26
+	"licenses" : ["MIT"]
  27
+}

0 notes on commit 4cf0f10

Please sign in to comment.
Something went wrong with that request. Please try again.