@@ -12,6 +12,7 @@ describe("The 'eval' method", function () {
12
12
13
13
describe ( "using " + parser + " and " + ip , function ( ) {
14
14
var client ;
15
+ var source = "return redis.call('set', 'sha', 'test')" ;
15
16
16
17
beforeEach ( function ( done ) {
17
18
client = redis . createClient . apply ( redis . createClient , args ) ;
@@ -94,31 +95,41 @@ describe("The 'eval' method", function () {
94
95
} ) ;
95
96
} ) ;
96
97
98
+ it ( 'allows a script to be executed that accesses the redis API without callback' , function ( done ) {
99
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
100
+ client . eval ( source , 0 ) ;
101
+ client . get ( 'sha' , helper . isString ( 'test' , done ) ) ;
102
+ } ) ;
103
+
97
104
describe ( 'evalsha' , function ( ) {
98
- var source = "return redis.call('get', 'sha test')" ;
99
105
var sha = crypto . createHash ( 'sha1' ) . update ( source ) . digest ( 'hex' ) ;
100
106
101
- beforeEach ( function ( done ) {
102
- client . set ( "sha test" , "eval get sha test" , function ( err , res ) {
103
- return done ( err ) ;
104
- } ) ;
105
- } ) ;
106
-
107
107
it ( 'allows a script to be executed that accesses the redis API' , function ( done ) {
108
108
helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
109
- client . eval ( source , 0 , helper . isString ( 'eval get sha test' , done ) ) ;
109
+ client . eval ( source , 0 , helper . isString ( 'OK' ) ) ;
110
+ client . get ( 'sha' , helper . isString ( 'test' , done ) ) ;
110
111
} ) ;
111
112
112
113
it ( 'can execute a script if the SHA exists' , function ( done ) {
113
114
helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
114
- client . evalsha ( sha , 0 , helper . isString ( 'eval get sha test' , done ) ) ;
115
+ client . evalsha ( sha , 0 , helper . isString ( 'OK' ) ) ;
116
+ client . get ( 'sha' , helper . isString ( 'test' , done ) ) ;
115
117
} ) ;
116
118
117
119
it ( 'returns an error if SHA does not exist' , function ( done ) {
118
120
helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
119
121
client . evalsha ( 'ffffffffffffffffffffffffffffffffffffffff' , 0 , helper . isError ( done ) ) ;
120
122
} ) ;
121
123
124
+ it ( 'emit an error if SHA does not exist without any callback' , function ( done ) {
125
+ helper . serverVersionAtLeast . call ( this , client , [ 2 , 5 , 0 ] ) ;
126
+ client . evalsha ( 'ffffffffffffffffffffffffffffffffffffffff' , 0 ) ;
127
+ client . on ( 'error' , function ( err ) {
128
+ assert ( / N O S C R I P T N o m a t c h i n g s c r i p t . P l e a s e u s e E V A L ./ . test ( err . message ) ) ;
129
+ done ( ) ;
130
+ } ) ;
131
+ } ) ;
132
+
122
133
it ( 'emits an error if SHA does not exist and no callback has been provided' , function ( done ) {
123
134
client . on ( 'error' , function ( err ) {
124
135
assert . equal ( err . message , 'NOSCRIPT No matching script. Please use EVAL.' ) ;
0 commit comments